

var jsVersion = +new Date() // '?v=202106091751';
var contextPath = '.'
if (getPageN() === 'index' || getPageN() === 'home') {
  contextPath = '.'
} else {
  contextPath = '..'
}
// css
// CSS 统一加载
document.write(`
  <link rel="icon" href="${contextPath}/image/favicon.ico">
  <link rel="stylesheet" href="${contextPath}/css/normalize.css">
  <link rel="stylesheet" href="${contextPath}/css/vant.css">
  <link rel="stylesheet" href="${contextPath}/css/common.css?rev=${jsVersion}">
`)

/**
 * 爱山东 jssdk相关引用
 */
document.write(`
  <script type="text/javascript" src="https://isdapp.shandong.gov.cn/jmopen/jssdk/index.js"></script>
  <script type="text/javascript" src="${contextPath}/sdk/jssdk2/aes.js"></script>
  <script type="text/javascript" src="${contextPath}/sdk/jssdk2/sm2/build/SM.js"></script>
`)
// 移动端 debugger 调试
if (localStorage.getItem('debug')=='Y') {
	document.write(
	  `<script type="text/javascript" src="${contextPath}/sdk/eruda-2.4.1.js"></script>\
					<script>eruda.init();</script>`
	)
}

// 自动识别环境（需在文件最顶部添加）
window.env = window.location.hostname.indexOf('isdapp.shandong.gov.cn') > -1  ? 'pro' : 'dev';


/**
 * 项目业务相关 js
 */
// <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/vant/2.12.54/vant.min.js"></script>\
// <script type="text/javascript" src="' + contextPath + '/sdk/vant.min.js"></script>\
// <script type="text/javascript" src="' + contextPath + '/sdk/axios.min.js"></script>\
document.write(`
   <script type="text/javascript" src="${contextPath}/sdk/vue.min.js"></script>
   <script type="text/javascript" src="${contextPath}/sdk/vant.min.js"></script>
   <script type="text/javascript" src="${contextPath}/sdk/flexible.js"></script>
   <script type="text/javascript" src="${contextPath}/sdk/util.js?rev=${jsVersion}"></script>
   <script type="text/javascript" src="${contextPath}/sdk/jssdk2/apiKeyMap.js?rev=${jsVersion}"></script>
	<script type="text/javascript" src="${contextPath}/sdk/axios.min.js"></script>
`)

let writeText = ''
if (window.env == 'dev') {
	

  const tempTk = 
      // 网格员
  'Bearer eyJhbGciOiJIUz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XQFHkGdRoxX18YFYNXAUgrFPYE8LO6sq6IwTFtQ'
    // 管理员 本地
		// 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiNGUyMGIzZTktNjNmMi00NTQxLWI0YzctYTg2MTRiZjM0MjM1In0.AIzbt4tD03_u-MvgIy7ZsYpvUz1Yy_ZBhsy_vvWo8S1rpGGSV8qDFmx31VHYgZYc37yYhz3MYGpnpARnBR3aXA'
  // 街道
  // 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJqaWVkYW8iLCJsb2dpbl91c2VyX2tleSI6ImNjNjRkMmZhLWQzNmItNGRkZi05MjcxLTliYTA0ZDJkYzM4NiJ9.G2BAs3XnlqR6QgDRWDfXkOpdLYhFdqEaTxvE8GxLAgU8vcsHPEKdhQ4VvOwsiNAtIaUpMDXirOb-FrHVNvZo4g'

  _setCookie('token', tempTk)

  const tempApiHost = 'http://192.168.2.37:8080'
  // const tempApiHost = 'https://gqyjpt.weihai.cn/prod-api'

  localStorage.setItem('apiHost', tempApiHost)


  writeText = `
  <script type="text/javascript" src="${contextPath}/sdk/axios_http.js"></script>
`
} else {
  writeText = `
   <script type="text/javascript" src="${contextPath}/sdk/http.js?rev=${jsVersion}"></script>
 `
}


document.write(writeText)
if (getPageN()) {
  // 加载同名js
  document.write('<script type="text/javascript" src="./' + getPageN() + '.js?rev=' + jsVersion + '"></script>')
  document.write('<link rel="stylesheet" type="text/css" href="./' + getPageN() + '.css?rev=' + jsVersion + '" />')
}

function getPageN() {
  var pageN = window.location.pathname
  pageN = pageN.substring(pageN.lastIndexOf('/') + 1, pageN.indexOf('.'))
  return pageN
}

// 新增浏览器地址变化监听
window.addEventListener('popstate', function () {
  vant.Toast.loading({
    message: '加载中...',
    forbidClick: true,
    loadingType: 'spinner'
  });
});



function _setCookie(name, value, days) {
  var len = arguments.length
  if (len == 2) {
    var exp = new Date()
    exp.setTime(exp.getTime() + 30 * 24 * 60 * 60 * 1000)
    document.cookie =
      name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';path=/'
  } else if (len == 3) {
    var exp = new Date()
    exp.setDate(exp.getDate() + parseInt(days))
    exp.setHours(1, 0, 0, 0)
    document.cookie =
      name + '=' + escape(value) + ';expires=' + exp.toGMTString() + ';path=/'
  }
}