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 |  144 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 114 insertions(+), 30 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 08baa38..1487f05 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -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')
@@ -403,6 +474,7 @@
     CacheUtils.updateWebSqlversion('1.00', curTime)
     CacheUtils.clearIndexDBConfig()
     CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime})
+    CacheUtils.clearFuncs(options.sysType)
   }
 
   /**
@@ -478,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) { // 缂栬緫鐘舵�侊紝涓斿瓨鍦ㄤ簯绔湴鍧�
@@ -665,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
   }
@@ -675,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') || ''
@@ -695,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)
@@ -730,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
     })
@@ -852,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