From e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 17 十月 2022 17:57:34 +0800
Subject: [PATCH] 2022-10-17

---
 src/api/index.js |  276 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 196 insertions(+), 80 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 1311362..d86149f 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -10,16 +10,19 @@
 
 window.GLOB.WebSql = null
 window.GLOB.IndexDB = null
-const systemMenuKeys = `1581067625930haged11ieaivpavv77k,1581734956310scks442ul2d955g9tu5,1583991994144ndddg0bhh0is6shi0v1,1583979633842550imkchl4qt4qppsiv,1578900109100np8aqd0a77q3na46oas,16044812935562g807p3p12huk8kokmb,
+const systemMenuKeys = `1581067625930haged11ieaivpavv77k,1581734956310scks442ul2d955g9tu5,1583991994144ndddg0bhh0is6shi0v1,1583979633842550imkchl4qt4qppsiv,1578900109100np8aqd0a77q3na46oas,
   1585192949946f3et2ts8tn82krmumdf,15855615451212m12ip23vpcm79kloro,1587005717541lov40vg61q7l1rbveon,1590458676585agbbr63t6ihighg2i1g,1602315375262ikd33ii0nii34pt861o,1582771068837vsv54a089lgp45migbg,
   1582777675954ifu05upurs465omoth7,158294809668898cklbv6c5bou8e1fpu,1584676379094iktph45fb8imhg96bql,1584695125339vo5g7iqgfn01qmrd6s2,1584699661372vhmpp9dn9foo0eob722,15848421131551gg04ie8sitsd3f7467,
-  1589782279158ngr675kk3oksin35sul,1589788042787ffdt9hle4s45k9r1nvs,15900310928174dro07ihfckghpb5h13,1594095599055qicg2eb642v5qglhnuo,1599613340050c8nu6rbst9d4emnnbsq,1577972969199lei1g0qkvlh4tkc908m,
+  1589782279158ngr675kk3oksin35sul,1589788042787ffdt9hle4s45k9r1nvs,1594095599055qicg2eb642v5qglhnuo,1577972969199lei1g0qkvlh4tkc908m,16044812935562g807p3p12huk8kokmb,
   1578479100252lfbp29v1kafk4s4q4ig,1577971621421tg4v0i1ur8873k7e0ob,1577929944419lgc5h3hepum765e2k7u,1588493493409k9guqp067d31lu7blsv,15827879285193g85m3i2uprektpgmpf`
 
+let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : ''
+let db = `mkdb${service}`
+
 if (window.openDatabase) {
-  CacheUtils.openWebSql(options.sysType)
+  CacheUtils.openWebSql(db)
 } else if (window.indexedDB) {
-  CacheUtils.openIndexDB(options.sysType)
+  CacheUtils.openIndexDB(db)
 }
 
 axios.defaults.crossDomain = true
@@ -81,11 +84,7 @@
 
 class Api {
   constructor() {
-    if (process.env.NODE_ENV === 'production') {
-      axios.defaults.baseURL = document.location.origin + '/' + window.GLOB.service
-    } else {
-      axios.defaults.baseURL = window.GLOB.location + '/' + window.GLOB.service
-    }
+    axios.defaults.baseURL = window.GLOB.baseurl
   }
   
   /**
@@ -96,7 +95,7 @@
     param.userid = param.userid || ''
 
     return axios({
-      url: '/webapi/dostar',
+      url: `/webapi/dostar${param.func ? '/' + param.func : ''}`,
       method: 'post',
       data: param
     })
@@ -106,7 +105,7 @@
    * @description 寰俊涓氬姟璇锋眰
    */
   wxAccessToken () {
-    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/getaccesstoken'
+    let _url = window.GLOB.baseurl + 'wxpay/getaccesstoken'
     if (process.env.NODE_ENV !== 'production') {
       _url = document.location.origin + '/wxpay/getaccesstoken'
     }
@@ -205,7 +204,7 @@
   /**
    * @description 娓稿鐧诲綍
    */
-  getTouristMsg (appid, openid, memberid, scanId) {
+  getTouristMsg (binding_type, appid, openid, memberid, scanId) {
     let _SessionUid = localStorage.getItem('SessionUid')
 
     if (!_SessionUid) { // 鎵嬪姩娓呴櫎SessionUid鏃讹紝瀹炴椂鐢熸垚
@@ -220,24 +219,39 @@
       TypeCharOne: 'pc',
       kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host))
     }
-    
-    param.LText = md5(window.btoa(_SessionUid + param.timestamp))
-    param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
-
-    param.appkey = window.GLOB.appkey || ''
-
-    if (appid) {
-      param.binding_type = 'mk'
-      param.thd_party_member_id = memberid
-      param.thd_party_openid = openid
-      param.thd_party_appid = appid
-      param.id = scanId
-    }
 
     let url = '/webapi/dologon/s_visitor_login'
     if (window.GLOB.mainSystemApi) {
       param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
     }
+
+    if (binding_type === 'mk') {
+      param.binding_type = 'mk'
+      param.thd_party_member_id = memberid
+      param.thd_party_openid = openid
+      param.thd_party_appid = appid
+      param.id = scanId
+    } else if (binding_type === 'login_check') { // appid 姝ゆ椂涓虹洰鏍�
+      param.v_type = 'login_check'
+      param.LoginUID = sessionStorage.getItem('LoginUID') || ''
+      url = appid.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
+
+      if (!param.rduri) {
+        param.rduri = window.GLOB.baseurl + 'webapi/dologon/s_visitor_login'
+      }
+
+      param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html')
+    }
+    
+    param.LText = md5(window.btoa(_SessionUid + param.timestamp + (param.linkurl || '')))
+
+    // param.secretkey = md5(param.LText + 'mingke' + param.timestamp) // v_type 涓虹┖鏃�
+    let solt = md5((window.GLOB.appkey + window.btoa(window.GLOB.appkey + 'mingke') + 'mingke').toLowerCase()).slice(-6).toUpperCase()
+
+    param.v_type = param.v_type || 'Y'
+    param.secretkey = md5(param.LText + solt + param.timestamp)
+
+    param.appkey = window.GLOB.appkey || ''
 
     return axios({
       url: url,
@@ -363,20 +377,38 @@
     let app_datetime = sessionStorage.getItem('app_datetime')
     if (sys_datetime && app_datetime) {
       let seconds = Math.floor((new Date().getTime() - app_datetime) / 1000)
-      curTime = moment(sys_datetime, 'YYYY-MM-DD HH:mm:ss').add(seconds, 'seconds').format('YYYY-MM-DD HH:mm:ss') + '.000'
+      let _curTime = moment(sys_datetime, 'YYYY-MM-DD HH:mm:ss').add(seconds, 'seconds').format('YYYY-MM-DD HH:mm:ss') + '.000'
+      if (/^\d{4}-\d{2}-\d{2}/.test(_curTime)) {
+        curTime = _curTime
+      }
     }
 
     if (window.GLOB.WebSql) {
       return new Promise((resolve, reject) => {
         CacheUtils.getWebSqlVersion().then(msg => {
-          let modifydate = msg.createDate || curTime
-          if (modifydate.indexOf('Invalid date') > -1) {
-            modifydate = curTime
-          }
-
           let param = {
             func: 's_get_app_version',
-            modifydate
+            modifydate: msg.createDate
+          }
+
+          param.TypeCharOne = ''
+          param.typename = ''
+
+          if (!msg.createDate && !msg.menuids) {
+            CacheUtils.updateWebSqlversion('1.00', curTime)
+            resolve()
+            return
+          } else if (!msg.createDate) {
+            param.modifydate = curTime
+            param.menuids = window.btoa(msg.menuids)
+          } else if (msg.menuids) {
+            let d = localStorage.getItem(db)
+
+            if (!d || curTime.indexOf(d) === -1) {
+              param.menuids = window.btoa(msg.menuids)
+            }
+
+            localStorage.setItem(db, curTime.substr(0, 10))
           }
   
           this.getSystemConfig(param).then(res => {
@@ -384,29 +416,28 @@
               reject()
               return
             }
-            let clear = false
-            let version = '1.00'
-  
-            if (res.menu_data && res.menu_data.length > 0) {
-              res.menu_data.forEach(mid => {
+            
+            let list = res.menu_data || []
+
+            if (res.menu_del) {
+              list.push(...res.menu_del)
+            }
+
+            if (list.length > 0) {
+              let clear = false
+              list.forEach(mid => {
                 if (systemMenuKeys.indexOf(mid.menuid) > -1) {
                   clear = true
                 }
               })
-
+              let keys = list.map(mid => `'${mid.menuid}'`).join(',')
               if (clear) {
-                CacheUtils.clearWebSqlConfig()
-              } else {
-                let keys = res.menu_data.map(mid => `'${mid.menuid}'`).join(',')
-                CacheUtils.delWebSqlConfig(keys)
+                keys = ''
               }
+              CacheUtils.delWebSqlConfig(keys)
             }
-            
-            if (msg.version) {
-              CacheUtils.updateWebSqlTime(curTime)
-            } else {
-              CacheUtils.createWebSqlversion(version, curTime)
-            }
+
+            CacheUtils.updateWebSqlversion(res.app_version || '1.00', curTime)
   
             resolve()
           })
@@ -417,13 +448,29 @@
     } else {
       return new Promise((resolve, reject) => {
         CacheUtils.getIndexDBVersion().then(msg => {
-          let modifydate = msg.createDate || curTime
-          if (modifydate.indexOf('Invalid date') > -1) {
-            modifydate = curTime
-          }
           let param = {
             func: 's_get_app_version',
-            modifydate
+            modifydate: msg.createDate
+          }
+
+          param.TypeCharOne = ''
+          param.typename = ''
+
+          if (!msg.createDate && !msg.menuids) {
+            CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime})
+            resolve()
+            return
+          } else if (!msg.createDate) {
+            param.modifydate = curTime
+            param.menuids = window.btoa(msg.menuids)
+          } else if (msg.menuids) {
+            let d = localStorage.getItem(db)
+
+            if (!d || curTime.indexOf(d) === -1) {
+              param.menuids = window.btoa(msg.menuids)
+            }
+
+            localStorage.setItem(db, curTime.substr(0, 10))
           }
 
           this.getSystemConfig(param).then(res => {
@@ -431,25 +478,28 @@
               reject()
               return
             }
-            let clear = false
-            let version = '1.00'
   
-            if (res.menu_data && res.menu_data.length > 0) {
-              res.menu_data.forEach(mid => {
+            let list = res.menu_data || []
+
+            if (res.menu_del) {
+              list.push(...res.menu_del)
+            }
+
+            if (list.length > 0) {
+              let clear = false
+              list.forEach(mid => {
                 if (systemMenuKeys.indexOf(mid.menuid) > -1) {
                   clear = true
                 }
               })
-
+              let keys = list.map(mid => mid.menuid)
               if (clear) {
-                CacheUtils.clearIndexDBConfig()
-              } else {
-                let keys = res.menu_data.map(mid => `'${mid.menuid}'`)
-                CacheUtils.delIndexDBConfig(keys)
+                keys = ''
               }
+              CacheUtils.delIndexDBConfig(keys)
             }
 
-            CacheUtils.updateIndexDBversion({version: version, createDate: curTime})
+            CacheUtils.updateIndexDBversion({version: res.app_version || '1.00', createDate: curTime})
   
             resolve()
           })
@@ -464,12 +514,11 @@
    * @description 鏇存柊绯荤粺鐗堟湰淇℃伅锛屾竻绌洪厤缃俊鎭�
    */
   updateAppVersion () {
-    let curTime = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-    CacheUtils.clearWebSqlConfig()
-    CacheUtils.updateWebSqlversion('1.00', curTime)
-    CacheUtils.clearIndexDBConfig()
-    CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime})
-    CacheUtils.clearFuncs(options.sysType)
+    CacheUtils.delWebSqlConfig()
+    CacheUtils.updateWebSqlversion()
+    CacheUtils.delIndexDBConfig()
+    CacheUtils.updateIndexDBversion()
+    CacheUtils.clearFuncs()
   }
 
   /**
@@ -553,7 +602,11 @@
       param.userid = sessionStorage.getItem('CloudUserID') || ''
       param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
     } else if (window.GLOB.mainSystemApi) {
-      url = window.GLOB.mainSystemApi
+      if (!window.GLOB.transfer) {
+        url = window.GLOB.mainSystemApi
+      } else {
+        param.rduri = window.GLOB.mainSystemApi
+      }
     }
 
     param = this.encryptParam(param)
@@ -583,7 +636,11 @@
         param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
       }
     } else if (window.GLOB.mainSystemApi) {
-      url = window.GLOB.mainSystemApi
+      if (!window.GLOB.transfer) {
+        url = window.GLOB.mainSystemApi
+      } else {
+        param.rduri = window.GLOB.mainSystemApi
+      }
     }
 
     let _param = JSON.parse(JSON.stringify(param)) // 缂撳瓨鏍¢獙锛屽幓闄ゆ椂闂村拰鍔犲瘑瀛楃
@@ -731,7 +788,7 @@
     param.appkey = window.GLOB.appkey || ''
 
     let url = '/webapi/dostars'
-    if (param.rduri) {
+    if (param.rduri && !window.GLOB.transfer) {
       url = param.rduri
       delete param.rduri
     }
@@ -774,19 +831,67 @@
     param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
     param.appkey = window.GLOB.appkey || ''
 
+    let login = false
+    let rduri = null
+
+    if (param.rduri && /\s|\n/.test(param.rduri)) {
+      param.rduri = param.rduri.replace(/\s|\n/g, '')
+      if (!param.rduri) {
+        delete param.rduri
+      }
+    }
+
+    if (param.$login && !window.GLOB.transfer) {
+      login = true
+      rduri = param.rduri || ''
+    }
+    delete param.$login
+
     let url = '/webapi/dostars'
-    if (param.rduri && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') { // 鍒囨崲鐢ㄦ埛闇�瑕侀�氳繃鏈湴
+
+    if (param.rduri && !window.GLOB.transfer && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
       url = param.rduri
       delete param.rduri
     }
 
     param = this.encryptParam(param)
 
-    return axios({
-      url: `${url}${param.func ? '/' + param.func : ''}`,
-      method: 'post',
-      data: param
-    })
+    if (login) {
+      let time = +sessionStorage.getItem(rduri)
+      let c_time = Math.round(new Date().getTime() / 1000)
+
+      if (time && c_time - time <= 60) {
+        sessionStorage.setItem(rduri, c_time)
+        return axios({
+          url: `${url}${param.func ? '/' + param.func : ''}`,
+          method: 'post',
+          data: param
+        })
+      }
+
+      return new Promise((resolve, reject) => {
+        this.getTouristMsg('login_check', rduri).then(res => {
+          if (res.status) {
+            sessionStorage.setItem(rduri, c_time)
+            axios({
+              url: `${url}${param.func ? '/' + param.func : ''}`,
+              method: 'post',
+              data: param
+            }).then(result => {
+              resolve(result)
+            })
+          } else {
+            resolve(res)
+          }
+        })
+      })
+    } else {
+      return axios({
+        url: `${url}${param.func ? '/' + param.func : ''}`,
+        method: 'post',
+        data: param
+      })
+    }
   }
 
   /**
@@ -857,8 +962,19 @@
     param = this.encryptParam(param)
 
     let url = '/webapi/SaveBase64Image'
+
     if (param.rduri) {
-      url = param.rduri.replace(/webapi(.*)$/, 'webapi/SaveBase64Image')
+      param.rduri = param.rduri.replace(/webapi(.*)$/, 'webapi/SaveBase64Image')
+      if (/\s|\n/.test(param.rduri)) {
+        param.rduri = param.rduri.replace(/\s|\n/g, '')
+        if (!param.rduri) {
+          delete param.rduri
+        }
+      }
+    }
+
+    if (param.rduri && !window.GLOB.transfer) {
+      url = param.rduri
       delete param.rduri
     }
 
@@ -922,7 +1038,7 @@
    * @description 鑾峰彇寰俊鏀粯浜岀淮鐮�
    */
   getWxNativePay (param) {
-    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/wxNativePay'
+    let _url = window.GLOB.baseurl + 'wxpay/wxNativePay'
     if (process.env.NODE_ENV !== 'production') {
       _url = document.location.origin + '/wxpay/wxNativePay'
     }

--
Gitblit v1.8.0