From 99966d855531d813197190f68e84f409f4eb1e61 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 三月 2022 18:50:37 +0800
Subject: [PATCH] 2022-03-10

---
 src/index.js |   96 ++++++++++++++++++++++++++---------------------
 1 files changed, 53 insertions(+), 43 deletions(-)

diff --git a/src/index.js b/src/index.js
index e03e548..033544f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,9 +10,7 @@
 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')
-} else if (window.location.href.indexOf('#/design') > -1) { // 缂栬緫椤甸潰鍒锋柊鏃讹紝璺宠浆鑷充富椤�
+if (window.location.href.indexOf('#/design') > -1) { // 缂栬緫椤甸潰鍒锋柊鏃讹紝璺宠浆鑷充富椤�
   window.location.replace(window.location.href.replace(/design/ig, 'main'))
 }
 
@@ -36,7 +34,7 @@
   })())
 }
 
-const render  = Component => {
+const render = Component => {
   ReactDOM.render(
     <Provider store={store}>
       <Component/>
@@ -45,42 +43,49 @@
   )
 }
 
-
-if (sessionStorage.getItem('loginError')) {
-  try {
-    let res = JSON.parse(sessionStorage.getItem('loginError'))
-    console.info(res.request)
-    console.info(res.response)
-  } catch {}
-}
 sessionStorage.removeItem('isEditState')
-sessionStorage.removeItem('loginError')
 sessionStorage.setItem('role_id', sessionStorage.getItem('localRole_id') || '')
 sessionStorage.setItem('dataM', sessionStorage.getItem('localDataM') || '')
 
-fetch(`./options.json`)
+// 鏂扮郴缁熸枃浠剁疆浜巃dmin涓� ../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
-    
+
+    if (config.defaultApp) {
+      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].replace('admin/', '') + 'mob/index.html#/index')
+        return
+      }
+    }
+
     let GLOB = {}
     GLOB.appId = config.appId || ''
     GLOB.lineColor = config.lineColor || ''
-    GLOB.filter = config.filter || ''
+    GLOB.licenseKey = config.licenseKey || ''
+    GLOB.probation = false
+    GLOB.watermark = config.watermark !== false
 
     if (config.externalDatabase !== false && config.externalDatabase !== 'false' && config.externalDatabase !== undefined) {
       GLOB.externalDatabase = config.externalDatabase ? `[${config.externalDatabase}]..` : ''
     } else {
       GLOB.externalDatabase = null
-
     }
 
     // 鍙湁涓氬姟绯荤粺鎵嶅彲浠ヨ缃负姝e紡绯荤粺
     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 if (options.sysType === 'local') {
+      GLOB.probation = true
+      GLOB.systemType = ''
     } else {
       GLOB.systemType = ''
     }
@@ -105,28 +110,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 && GLOB.watermark) {
           GLOB.dataFormat = true
         }
       
@@ -154,6 +147,8 @@
         GLOB.webSite = _systemMsg.webSite
         GLOB.style = _systemMsg.style
         GLOB.showline = _systemMsg.showline || ''
+        GLOB.navBar = _systemMsg.navBar || ''
+        GLOB.appVersion = _systemMsg.app_version || ''
 
         if (GLOB.favicon) {
           let link = document.querySelector("link[rel*='icon']") || document.createElement('link')
@@ -165,14 +160,14 @@
         if (GLOB.style && styles[GLOB.style]) {
           document.body.className = styles[GLOB.style] + ' ' + (GLOB.showline === 'false' ? 'hidden-split-line' : '')
         }
-      } catch {
+      } 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) {
@@ -181,16 +176,31 @@
     }
 
     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'
       }
       GLOB.service = _service ? _service + '/' : ''
+      GLOB.host = window.location.host + (_service ? '_' + _service : '')
     } else {
       GLOB.linkurl = ''
-      GLOB.location = 'http://qingqiumarket.cn'
-      GLOB.service = 'mkwms/'
+      GLOB.location = config.host
+      GLOB.service = config.service
+      GLOB.host = config.host.replace(/http(s)?:\/\//ig, '') + (config.service ? '_' + config.service.replace(/\//ig, '') : '')
+    }
+
+    let mark = sessionStorage.getItem('system_mark')
+    let _mark = `sys_${GLOB.service.replace('/', '') || 'service'}`
+    if (mark && mark !== _mark) {
+      sessionStorage.clear()
+    }
+    sessionStorage.setItem('system_mark', _mark)
+
+    if (localStorage.getItem(_href + 'lang')) {
+      sessionStorage.setItem('lang', localStorage.getItem(_href + 'lang'))
+    } else {
+      sessionStorage.setItem('lang', config.defaultLang !== 'en-US' ? 'zh-CN' : 'en-US')
     }
 
     Object.defineProperty(GLOB, 'appId', {

--
Gitblit v1.8.0