From cbeffcc0902631909c0373f274752a97ddaf2d4e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 06 八月 2022 01:41:54 +0800
Subject: [PATCH] 2022-08-06

---
 src/api/index.js |  171 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 124 insertions(+), 47 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index a695892..1487f05 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -14,7 +14,7 @@
   1585192949946f3et2ts8tn82krmumdf,15855615451212m12ip23vpcm79kloro,1587005717541lov40vg61q7l1rbveon,1590458676585agbbr63t6ihighg2i1g,1602315375262ikd33ii0nii34pt861o,1582771068837vsv54a089lgp45migbg,
   1582777675954ifu05upurs465omoth7,158294809668898cklbv6c5bou8e1fpu,1584676379094iktph45fb8imhg96bql,1584695125339vo5g7iqgfn01qmrd6s2,1584699661372vhmpp9dn9foo0eob722,15848421131551gg04ie8sitsd3f7467,
   1589782279158ngr675kk3oksin35sul,1589788042787ffdt9hle4s45k9r1nvs,15900310928174dro07ihfckghpb5h13,1594095599055qicg2eb642v5qglhnuo,1599613340050c8nu6rbst9d4emnnbsq,1577972969199lei1g0qkvlh4tkc908m,
-  1578479100252lfbp29v1kafk4s4q4ig,1577971621421tg4v0i1ur8873k7e0ob,1577929944419lgc5h3hepum765e2k7u,1588493493409k9guqp067d31lu7blsv`
+  1578479100252lfbp29v1kafk4s4q4ig,1577971621421tg4v0i1ur8873k7e0ob,1577929944419lgc5h3hepum765e2k7u,1588493493409k9guqp067d31lu7blsv,15827879285193g85m3i2uprektpgmpf`
 
 if (window.openDatabase) {
   CacheUtils.openWebSql(options.sysType)
@@ -29,7 +29,7 @@
 axios.interceptors.request.use((config) => {
   if (config.url.includes('LoginAndRedirect') || config.url.includes('getjsonresult') || config.url.includes('wxNativePay')) {
     config.data = qs.stringify(config.data)
-  } else if (config.url.includes('Upload') || config.url.includes('doupload') || config.url.includes('dopreload')) {
+  } else if (config.url.includes('doupload') || config.url.includes('dopreload')) {
     config.headers = { 'Content-Type': 'multipart/form-data' }
   } else if (config.method === 'post' && config.data) {
     config.data = JSON.stringify(config.data)
@@ -48,7 +48,7 @@
     }
 
     sessionStorage.clear()
-    sessionStorage.setItem('loginError', JSON.stringify({request: res.config ? res.config.data : '', response: JSON.stringify(res.data)}))
+    sessionStorage.setItem('loginError', JSON.stringify({url: res.config ? res.config.url : '', request: res.config ? res.config.data : '', response: JSON.stringify(res.data)}))
     window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login')
     window.location.reload()
   }
@@ -59,23 +59,29 @@
     if (window.debugger === true) {
       response.data.ErrCode = 'E'
       return Promise.resolve(response.data)
-    } else {
+    } else if (!sessionStorage.getItem('loginError')) {
       setCurrentUrl(response)
     }
   } else {
     return Promise.resolve(response.data)
   }
 }, (error) => {
-  if (error && error.response) {
-    notification.error({
-      className: 'notification-custom-error',
-      bottom: 0,
-      message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�',
-      placement: 'bottomRight',
-      duration: 15
-    })
+  let response = error.response
+
+  if (response) {
+    if (!response.data || !response.data.errors) { // 杩囨护鏃疯鎶ラ敊淇℃伅
+      notification.error({
+        className: 'notification-custom-error',
+        bottom: 0,
+        message: '鐘舵�佺爜-' + response.status + '锛岃鑱旂郴绠$悊鍛�',
+        placement: 'bottomRight',
+        duration: 15
+      })
+    }
+    return Promise.reject(response)
+  } else {
+    return Promise.reject()
   }
-  return Promise.reject(error.response)
 })
 
 class Api {
@@ -98,6 +104,69 @@
       url: '/webapi/dostar',
       method: 'post',
       data: param
+    })
+  }
+
+  /**
+   * @description 寰俊涓氬姟璇锋眰
+   */
+  wxAccessToken () {
+    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/getaccesstoken'
+    if (process.env.NODE_ENV !== 'production') {
+      _url = document.location.origin + '/wxpay/getaccesstoken'
+    }
+
+    return new Promise(resolve => {
+      if (window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) {
+        resolve(window.GLOB.accessToken)
+      } else {
+        window.GLOB.accessToken = {}
+        axios({
+          url: _url,
+          method: 'get'
+        }).then(res => {
+          if (res.oa_access_token || res.mini_access_token) {
+            window.GLOB.accessToken.accessTime = parseInt(new Date().getTime() / 1000)
+            window.GLOB.accessToken.oa_access_token = res.oa_access_token
+            window.GLOB.accessToken.mini_access_token = res.mini_access_token
+          }
+          resolve(res)
+        })
+      }
+    })
+  }
+
+  /**
+   * @description 寰俊涓氬姟璇锋眰
+   */
+  wxNginxRequest (url, method, param) {
+    let _url = window.GLOB.location + '/' + url
+    if (process.env.NODE_ENV === 'production') {
+      _url = document.location.origin + '/' + url
+    }
+    if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
+      _url = window.GLOB.location + ':8080/' + url
+      if (process.env.NODE_ENV === 'production') {
+        _url = document.location.origin + ':8080/' + url
+      }
+    } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
+      _url = window.GLOB.location + ':8443/' + url
+      if (process.env.NODE_ENV === 'production') {
+        _url = document.location.origin + ':8443/' + url
+      }
+    }
+    
+    if (param) {
+      return axios({
+        url: _url,
+        method,
+        data: param
+      })
+    }
+
+    return axios({
+      url: _url,
+      method
     })
   }
 
@@ -153,7 +222,8 @@
       func: 's_visitor_login',
       timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), 
       SessionUid: _SessionUid,
-      TypeCharOne: 'pc'
+      TypeCharOne: 'pc',
+      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host))
     }
     
     param.LText = md5(window.btoa(_SessionUid + param.timestamp))
@@ -171,7 +241,6 @@
 
     let url = '/webapi/dologon/s_visitor_login'
     if (window.GLOB.mainSystemApi) {
-      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
       param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
     }
 
@@ -195,7 +264,9 @@
       way_no: 'sms_vcode',
       systemType: options.sysType,
       login_city: city,
-      login_id_address: ipAddress
+      login_id_address: ipAddress,
+      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
+      device_id: localStorage.getItem('SessionUid')
     }
 
     param.appkey = window.GLOB.appkey || ''
@@ -204,14 +275,12 @@
     if (isCloud) {
       param.debug = 'Y'
       if (options.cloudServiceApi) {
-        // url = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
         param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
       }
     } else if (window.GLOB.mainSystemApi) {
       if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
         param.linkurl = window.GLOB.linkurl
       }
-      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
       param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
     }
 
@@ -232,7 +301,9 @@
       systemType: options.sysType,
       Type: 'S',
       login_city: city,
-      login_id_address: ipAddress
+      login_id_address: ipAddress,
+      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
+      device_id: localStorage.getItem('SessionUid')
     }
 
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
@@ -288,7 +359,6 @@
    * @description 鑾峰彇绯荤粺鐗堟湰淇℃伅锛屽惎鐢ㄦ垨鏇存柊websql
    */
   getAppVersion (_resolve, _reject) {
-    let appVersion = {}
     if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
       return Promise.reject()
     }
@@ -304,7 +374,6 @@
     if (window.GLOB.WebSql) {
       return new Promise((resolve, reject) => {
         CacheUtils.getWebSqlVersion().then(msg => {
-          appVersion.oldVersion = msg.version || ''
           let modifydate = msg.createDate || curTime
           if (modifydate.indexOf('Invalid date') > -1) {
             modifydate = curTime
@@ -321,9 +390,7 @@
               return
             }
             let clear = false
-            let version = res.app_version || '1.00'
-            appVersion.newVersion = version
-            appVersion.oldVersion = appVersion.oldVersion || version
+            let version = '1.00'
   
             if (res.menu_data && res.menu_data.length > 0) {
               res.menu_data.forEach(mid => {
@@ -346,7 +413,7 @@
               CacheUtils.createWebSqlversion(version, curTime)
             }
   
-            resolve(appVersion)
+            resolve()
           })
         }, () => {
           reject()
@@ -355,7 +422,6 @@
     } else {
       return new Promise((resolve, reject) => {
         CacheUtils.getIndexDBVersion().then(msg => {
-          appVersion.oldVersion = msg.version || ''
           let modifydate = msg.createDate || curTime
           if (modifydate.indexOf('Invalid date') > -1) {
             modifydate = curTime
@@ -371,9 +437,7 @@
               return
             }
             let clear = false
-            let version = res.app_version || '1.00'
-            appVersion.newVersion = version
-            appVersion.oldVersion = appVersion.oldVersion || version
+            let version = '1.00'
   
             if (res.menu_data && res.menu_data.length > 0) {
               res.menu_data.forEach(mid => {
@@ -390,9 +454,9 @@
               }
             }
 
-            CacheUtils.updateIndexDBversion({version: appVersion.oldVersion, createDate: curTime})
+            CacheUtils.updateIndexDBversion({version: version, createDate: curTime})
   
-            resolve(appVersion)
+            resolve()
           })
         }, () => {
           reject()
@@ -404,12 +468,13 @@
   /**
    * @description 鏇存柊绯荤粺鐗堟湰淇℃伅锛屾竻绌洪厤缃俊鎭�
    */
-  updateAppVersion (newVersion) {
+  updateAppVersion () {
     let curTime = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
     CacheUtils.clearWebSqlConfig()
-    CacheUtils.updateWebSqlversion(newVersion, curTime)
+    CacheUtils.updateWebSqlversion('1.00', curTime)
     CacheUtils.clearIndexDBConfig()
-    CacheUtils.updateIndexDBversion({version: newVersion, createDate: curTime})
+    CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime})
+    CacheUtils.clearFuncs(options.sysType)
   }
 
   /**
@@ -485,7 +550,7 @@
     param.lang = param.lang || sessionStorage.getItem('lang') || ''
     param.SessionUid = localStorage.getItem('SessionUid') || ''
     param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
-    param.appkey = window.GLOB.appkey || ''
+    param.appkey = param.appkey || window.GLOB.appkey
 
     let url = '/webapi/dostars'
     if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { // 缂栬緫鐘舵�侊紝涓斿瓨鍦ㄤ簯绔湴鍧�
@@ -672,7 +737,15 @@
       }
     })
     param.sign = md5(values)
-    param.t = new Date().getTime()
+    param.t = new Date().getTime();
+
+    ['arr_field', 'LText_field', 'custom_script', 'LText1', 'LText', 'LText2', 'DateCount'].forEach(key => {
+      if (param[key]) {
+        let val = param[key]
+        delete param[key]
+        param[key] = val
+      }
+    })
 
     return param
   }
@@ -682,7 +755,7 @@
    * @param {Object}  param   璇锋眰鍙傛暟
    * @param {Boolean} SSO     鏄惁涓哄崟鐐圭櫥褰曞湴鍧�
    */
-  getSystemCacheConfig (param) {
+  getSystemCacheConfig (param, cache = true) {
     param.userid = param.userid || sessionStorage.getItem('UserID') || ''
     param.lang = param.lang || sessionStorage.getItem('lang') || ''
     param.SessionUid = localStorage.getItem('SessionUid') || ''
@@ -702,7 +775,7 @@
     _param = JSON.stringify(_param)
     _param  = md5(_param)
 
-    if (window.GLOB.CacheMap.has(_param)) {
+    if (cache && window.GLOB.CacheMap.has(_param)) {
       return Promise.resolve(window.GLOB.CacheMap.get(_param))
     } else {
       param = this.encryptParam(param)
@@ -737,17 +810,16 @@
       param.LoginUID = sessionStorage.getItem('CloudLoginUID') || param.LoginUID || ''
     }
 
-    // 寰呬紭鍖栵紝澧炲姞鏄惁鏀寔璺ㄥ煙璇锋眰
-    // let url = '/webapi/dostars'
-    // if (param.rduri) {
-    //   url = param.rduri
-    //   delete param.rduri
-    // }
+    let url = '/webapi/dostars'
+    if (param.rduri && /\/dostars/.test(param.rduri)) {
+      url = param.rduri
+      delete param.rduri
+    }
 
     param = this.encryptParam(param)
 
     return axios({
-      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+      url: `${url}${param.func ? '/' + param.func : ''}`,
       method: 'post',
       data: param
     })
@@ -792,7 +864,7 @@
             }
             resolve()
           }
-        } catch {
+        } catch (e) {
           resolve({
             ErrCode: 'E',
             ErrMesg: '鏂囦欢瑙f瀽閿欒',
@@ -859,8 +931,13 @@
    * @description 鑾峰彇寰俊鏀粯浜岀淮鐮�
    */
   getWxNativePay (param) {
+    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/wxNativePay'
+    if (process.env.NODE_ENV !== 'production') {
+      _url = document.location.origin + '/wxpay/wxNativePay'
+    }
+
     return axios({
-      url: '/wxpay/wxNativePay',
+      url: _url,
       method: 'post',
       data: param
     })

--
Gitblit v1.8.0