From fc241324087e605b145e8bbcc4ee3aece61dbf14 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 21 三月 2022 15:59:45 +0800
Subject: [PATCH] 2022-03-21

---
 src/index.js |  107 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 66 insertions(+), 41 deletions(-)

diff --git a/src/index.js b/src/index.js
index 3f455ef..bb2bff3 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,15 +43,7 @@
   )
 }
 
-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') || '')
 
@@ -67,11 +57,19 @@
   .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.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}]..` : ''
@@ -85,41 +83,54 @@
       if (config.probation && /^20\d{2}-\d{2}-\d{2}$/.test(config.probation) && new Date(config.probation).getTime() > new Date().getTime()) {
         GLOB.probation = true
       }
+
+      if (!config.mainSystemApi) {
+        document.getElementById('root').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh;">绯荤粺鏈缃崟鐐瑰湴鍧�锛岃鑱旂郴绠$悊鍛橈紒</div>'
+        return
+      } else if (/http(s?):\/\/sso.mk9h.cn\/cloud/ig.test(config.mainSystemApi)) {
+        document.getElementById('root').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh;">姝e紡绯荤粺涓嶅彲浣跨敤 http://sso.mk9h.cn/cloud 鍋氫负鍗曠偣鍦板潃锛岃鑱旂郴绠$悊鍛橈紒</div>'
+        return
+      } else if (/http(s?):\/\/cloud.mk9h.cn/ig.test(config.mainSystemApi)) {
+        document.getElementById('root').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh;">姝e紡绯荤粺涓嶅彲浣跨敤 http://cloud.mk9h.cn 鍋氫负鍗曠偣鍦板潃锛岃鑱旂郴绠$悊鍛橈紒</div>'
+        return
+      }
+    } else if (options.sysType === 'local') {
+      GLOB.probation = true
+      GLOB.systemType = ''
+
+      // GLOB.mainSystemApi = 'https://cloud.positecgroup.com/webapi/dostars'
+
+      GLOB.mainSystemApi = 'http://sso.mk9h.cn/cloud/webapi/dostars'
+
+      if (GLOB.watermark) {
+        GLOB.dataFormat = true
+      }
     } else {
       GLOB.systemType = ''
+      GLOB.mainSystemApi = ''
+    }
+
+    GLOB.debugger = options.sysType === 'local' && GLOB.systemType !== 'production'
+
+    if (options.sysType !== 'cloud') {
+      if (config.appkey === options.cakey) {
+        document.getElementById('root').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh;">涓嶅彲浣跨敤浜戠appkey锛岃鑱旂郴绠$悊鍛橈紒</div>'
+        return
+      }
     }
 
     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
-      }
+      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) {
+      GLOB.appkey = config.appkey
+      if (GLOB.systemType === 'production') {
         let systemApi = config.mainSystemApi
-        // 涓氬姟绯荤粺涓嶅厑璁歌繛鎺ヤ簯绔紝涓氬姟绯荤粺杩炴帴sso.mk9h.cn鏃讹紝鏁版嵁铏氬寲澶勭悊
-        if (systemApi.indexOf('cloud.mk9h.cn') > -1) {
-          systemApi = ''
-        } else if (/index.html/ig.test(systemApi)) {
+        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
         }
       
         GLOB.mainSystemApi = systemApi
@@ -127,12 +138,6 @@
     }
 
     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')
 
@@ -153,6 +158,7 @@
         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')
@@ -186,10 +192,25 @@
         GLOB.linkurl = GLOB.linkurl + 'index.html'
       }
       GLOB.service = _service ? _service + '/' : ''
+      GLOB.host = window.location.host + (_service ? '_' + _service : '')
     } else {
       GLOB.linkurl = ''
       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', {
@@ -204,6 +225,10 @@
       writable: false,
       value: GLOB.systemType
     })
+    Object.defineProperty(GLOB, 'debugger', {
+      writable: false,
+      value: GLOB.debugger
+    })
     Object.defineProperty(GLOB, 'mainSystemApi', {
       writable: false,
       value: GLOB.mainSystemApi

--
Gitblit v1.8.0