king
2020-08-20 3683e1475e8d74f690172a468518d88d91a69ccc
src/index.js
@@ -4,8 +4,35 @@
import {Provider} from 'react-redux'
import store from '@/store'
import * as serviceWorker from './serviceWorker'
import options from '@/store/options.js'
import '@/assets/css/main.scss'
import '@/assets/css/action.scss'
import '@/assets/css/minkeicon.css'
import '@/assets/css/viewstyle.scss'
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  window.location.replace(window.location.href.split(/(index.html)+/ig)[0] + 'mob/index.html')
}
options.sysType = window.atob(options.sysType.replace('$mk', ''))
options.caId = window.atob(options.caId.replace('$mk', ''))
options.cakey = window.atob(options.cakey.replace('$mk', ''))
options.cdomain = window.atob(options.cdomain.replace('$mk', ''))
if (options.cdomain && options.sysType !== 'cloud') {
  options.cloudServiceApi = options.cdomain + '/webapi/dostars'
}
if (!localStorage.getItem('SessionUid')) {
  localStorage.setItem('SessionUid', (() => {
    let uuid = []
    let _options = '0123456789abcdefghigklmnopqrstuv'
    for (let i = 0; i < 32; i++) {
      uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
    }
    return uuid.join('')
  })())
}
const render  = Component => {
  ReactDOM.render(
@@ -16,6 +43,168 @@
  )
}
render(Route)
sessionStorage.removeItem('isEditState')
fetch(`./${process.env.NODE_ENV === 'production' ? 'build/' : ''}options.json`)
  .then(response => response.json())
  .catch(() => {
    console.warn('系统配置信息获取失败,请联系管理员!')
  })
  .then(config => {
    if (!config) return
    let GLOB = {}
    GLOB.appId = config.appId || ''
    GLOB.lineColor = config.lineColor || ''
    GLOB.filter = config.filter || ''
    // 只有业务系统才可以设置为正式系统
    if (options.sysType === 'local' && (config.systemType === 'official' || config.systemType === 'production')) {
      GLOB.systemType = 'production'
    } else {
      GLOB.systemType = ''
    }
    if (options.sysType === 'cloud') { // cloud不可设置单点服务器地址,云端appkey为系统设置
      GLOB.appkey = options.cakey
      GLOB.mainSystemApi = ''
    } else if (options.sysType === 'SSO') { // sso不可设置单点服务器地址
      GLOB.mainSystemApi = ''
      if (config.appkey === options.cakey) {
        GLOB.appkey = ''
        console.warn('单点系统appkey不可与云端相同')
      } else {
        GLOB.appkey = config.appkey
      }
    } else if (options.sysType === 'local') { // 业务系统
      if (config.appkey === options.cakey) {
        GLOB.appkey = ''
        console.warn('业务系统appkey不可与云端相同')
      } else {
        GLOB.appkey = config.appkey
      }
      if (config.mainSystemApi) {
        let systemApi = config.mainSystemApi
        // if (/^(http|https):\/\//ig.test(systemApi)) {
        //   let _systemApi = /^(http|https):\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62}|(:[0-9]{1,4}))+\.?/ig.exec(systemApi)
        //   systemApi = _systemApi ? _systemApi[0] : ''
        // } else {
        //   systemApi = ''
        // }
        // // 业务系统连接云端时,格式化处理
        // if (systemApi && systemApi === /^(http|https):\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62}|(:[0-9]{1,4}))+\.?/ig.exec(options.cloudServiceApi)[0]) {
        //   GLOB.dataFormat = true
        // }
        // if (systemApi) {
        //   systemApi = systemApi + '/webapi/dostars'
        // }
        // 业务系统不允许连接云端,业务系统连接sso.mk9h.cn时,数据虚化处理
        if (systemApi && systemApi.indexOf('cloud.mk9h.cn') > -1) {
          systemApi = ''
        } else if (systemApi && systemApi.indexOf('sso.mk9h.cn') > -1) {
          GLOB.dataFormat = true
        }
        GLOB.mainSystemApi = systemApi
      }
    }
    let _systemMsg = localStorage.getItem(window.location.href.split('#')[0] + 'system')
    if (_systemMsg) {
      try {
        _systemMsg = JSON.parse(window.decodeURIComponent(window.atob(_systemMsg)))
        GLOB.platTitle = _systemMsg.platTitle
        GLOB.platName = _systemMsg.platName
        GLOB.favicon = _systemMsg.favicon
        GLOB.loginlogo = _systemMsg.loginlogo
        GLOB.copyRight = _systemMsg.copyRight
        GLOB.ICP = _systemMsg.ICP
        GLOB.bgImage = _systemMsg.bgImage
        GLOB.mainlogo = _systemMsg.mainlogo
        GLOB.doclogo = _systemMsg.doclogo
        GLOB.webSite = _systemMsg.webSite
        GLOB.style = _systemMsg.style
        if (GLOB.favicon) {
          let link = document.querySelector("link[rel*='icon']") || document.createElement('link')
          link.type = 'image/x-icon'
          link.rel = 'shortcut icon'
          link.href = GLOB.favicon
          document.getElementsByTagName('head')[0].appendChild(link)
        }
      } catch {
        console.warn('Parse Failure')
      }
    }
    document.title = GLOB.platTitle || ''
    if (GLOB.filter === 'true') {
      let html = document.getElementsByTagName('html')[0]
      if (html) {
        html.style.filter = 'grayscale(100%)'
      }
    }
    if (process.env.NODE_ENV === 'production') { // 用于校验是否存在开发权限
      let _service = window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '').replace(new RegExp(document.location.origin + '/?', 'ig'), '')
      GLOB.linkurl = window.location.href.split('#')[0]
      if (!/index.html/ig.test(GLOB.linkurl)) {
        GLOB.linkurl = GLOB.linkurl + 'index.html'
      }
      GLOB.service = _service ? _service + '/' : ''
    } else {
      GLOB.linkurl = ''
      GLOB.location = 'http://qingqiumarket.cn/'
      GLOB.service = 'mkwms/'
    }
    const option = {
      white: 'mk-white'
    }
    if (GLOB.style && option[GLOB.style]) {
      document.getElementById('root').className = option[GLOB.style]
    }
    Object.defineProperty(GLOB, 'appId', {
      writable: false,
      value: GLOB.appId
    })
    Object.defineProperty(GLOB, 'appkey', {
      writable: false,
      value: GLOB.appkey
    })
    Object.defineProperty(GLOB, 'systemType', {
      writable: false,
      value: GLOB.systemType
    })
    Object.defineProperty(GLOB, 'mainSystemApi', {
      writable: false,
      value: GLOB.mainSystemApi
    })
    Object.defineProperty(GLOB, 'linkurl', {
      writable: false,
      value: GLOB.linkurl
    })
    Object.defineProperty(GLOB, 'dataFormat', {
      writable: false,
      value: GLOB.dataFormat
    })
    Object.defineProperty(window, 'GLOB', {
      writable: false,
      value: GLOB
    })
    render(Route)
  })
serviceWorker.unregister()