king
2021-10-08 24bba05db141f358bf1a8bb7213a2432c9de355e
src/index.js
@@ -1,10 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Route from './router'
import {Provider} from 'react-redux'
import { Provider } from 'react-redux'
import store from '@/store'
import * as serviceWorker from './serviceWorker'
import options from '@/store/options.js'
import options, { styles } from '@/store/options.js'
import '@/assets/css/main.scss'
import '@/assets/css/action.scss'
import '@/assets/css/minkeicon.css'
@@ -12,6 +12,8 @@
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')
} else if (window.location.href.indexOf('#/design') > -1) { // 编辑页面刷新时,跳转至主页
  window.location.replace(window.location.href.replace(/design/ig, 'main'))
}
options.sysType = window.atob(options.sysType.replace('$mk', ''))
@@ -43,25 +45,46 @@
  )
}
if (sessionStorage.getItem('loginError')) {
  try {
    let res = JSON.parse(sessionStorage.getItem('loginError'))
    console.info(res.request)
    console.info(res.response)
  } catch (e) {}
}
sessionStorage.removeItem('isEditState')
sessionStorage.removeItem('loginError')
sessionStorage.setItem('role_id', sessionStorage.getItem('localRole_id') || '')
sessionStorage.setItem('dataM', sessionStorage.getItem('localDataM') || '')
// fetch(`./${process.env.NODE_ENV === 'production' ? 'build/' : ''}options.json`)
fetch(`./options.json`)
// 新系统文件置于admin中 ../options.json , { cache: 'no-cache'}
fetch('../options.json')
  .then(response => response.json())
  .catch(() => {
    console.warn('系统配置信息获取失败,请联系管理员!')
    document.getElementById('root').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh;">系统配置信息获取失败,请联系管理员!</div>'
  })
  .then(config => {
    if (!config) return
    let GLOB = {}
    GLOB.appId = config.appId || ''
    GLOB.lineColor = config.lineColor || ''
    GLOB.filter = config.filter || ''
    GLOB.licenseKey = config.licenseKey || ''
    GLOB.probation = false
    if (config.externalDatabase !== false && config.externalDatabase !== 'false' && config.externalDatabase !== undefined) {
      GLOB.externalDatabase = config.externalDatabase ? `[${config.externalDatabase}]..` : ''
    } else {
      GLOB.externalDatabase = null
    }
    // 只有业务系统才可以设置为正式系统
    if (options.sysType === 'local' && (config.systemType === 'official' || config.systemType === 'production')) {
      GLOB.systemType = 'production'
      if (config.probation && /^20\d{2}-\d{2}-\d{2}$/.test(config.probation) && new Date(config.probation).getTime() > new Date().getTime()) {
        GLOB.probation = true
      }
    } else {
      GLOB.systemType = ''
    }
@@ -86,28 +109,16 @@
      }
      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) {
        if (systemApi.indexOf('cloud.mk9h.cn') > -1) {
          systemApi = ''
        } else if (systemApi && systemApi.indexOf('sso.mk9h.cn') > -1 && process.env.NODE_ENV === 'production') {
        } else if (/index.html/ig.test(systemApi)) {
          systemApi = systemApi.replace(/index.html.*/ig, 'webapi/dostars')
        } else if (!/webapi\/dostars$/ig.test(systemApi)) {
          systemApi = systemApi.replace(/\/?$/, '/webapi/dostars')
        }
        if (systemApi.indexOf('sso.mk9h.cn') > -1 && process.env.NODE_ENV === 'production') {
          GLOB.dataFormat = true
        }
      
@@ -116,6 +127,12 @@
    }
    let _href = window.location.href.split('#')[0]
    if (localStorage.getItem(_href + 'lang')) {
      sessionStorage.setItem('lang', localStorage.getItem(_href + 'lang'))
    } else {
      sessionStorage.setItem('lang', config.defaultLang !== 'en-US' ? 'zh-CN' : 'en-US')
    }
    let _systemMsg = localStorage.getItem(_href + 'system')
@@ -134,6 +151,8 @@
        GLOB.doclogo = _systemMsg.doclogo
        GLOB.webSite = _systemMsg.webSite
        GLOB.style = _systemMsg.style
        GLOB.showline = _systemMsg.showline || ''
        GLOB.navBar = _systemMsg.navBar || ''
        if (GLOB.favicon) {
          let link = document.querySelector("link[rel*='icon']") || document.createElement('link')
@@ -142,14 +161,17 @@
          link.href = GLOB.favicon
          document.getElementsByTagName('head')[0].appendChild(link)
        }
      } catch {
        if (GLOB.style && styles[GLOB.style]) {
          document.body.className = styles[GLOB.style] + ' ' + (GLOB.showline === 'false' ? 'hidden-split-line' : '')
        }
      } catch (e) {
        console.warn('Parse Failure')
      }
    }
    document.title = GLOB.platTitle || ''
    if (GLOB.filter === 'true') {
    if (config.filter === 'true') {
      let html = document.getElementsByTagName('html')[0]
      
      if (html) {
@@ -158,7 +180,7 @@
    }
    if (process.env.NODE_ENV === 'production') { // 用于校验是否存在开发权限
      let _service = window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '').replace(new RegExp(document.location.origin + '/?', 'ig'), '')
      let _service = window.location.href.replace(/(\/admin)?\/index.html(.*)|(\/admin)?\/#(.*)/ig, '').replace(new RegExp(document.location.origin + '/?', 'ig'), '')
      GLOB.linkurl = _href
      if (!/index.html/ig.test(GLOB.linkurl)) {
        GLOB.linkurl = GLOB.linkurl + 'index.html'
@@ -166,12 +188,8 @@
      GLOB.service = _service ? _service + '/' : ''
    } else {
      GLOB.linkurl = ''
      GLOB.location = 'http://qingqiumarket.cn/'
      GLOB.service = 'mkwms/'
    }
    if (GLOB.style && options.styles[GLOB.style]) {
      document.getElementById('root').className = options.styles[GLOB.style]
      GLOB.location = config.host
      GLOB.service = config.service
    }
    Object.defineProperty(GLOB, 'appId', {
@@ -203,6 +221,9 @@
      value: GLOB
    })
    window.GLOB.CacheMap = new Map()     // 缓存配置信息
    window.GLOB.UserCacheMap = new Map() // 缓存用户自定义设置
    render(Route)
  })