From 4771f0fa8bc2238e9ad005ea23a8d4c7576cd416 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 18 七月 2022 14:57:17 +0800
Subject: [PATCH] 2022-07-18

---
 src/api/index.js |  105 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 88 insertions(+), 17 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index c47a9cc..574fa7a 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,61 @@
       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 + ':8080/' + url
+    if (process.env.NODE_ENV === 'production') {
+      _url = document.location.origin + ':8080/' + url
+    }
+    if (/https/.test(_url)) {
+      _url = _url.replace(/:8080/g, ':8443')
+    }
+    
+    if (param) {
+      return axios({
+        url: _url,
+        method,
+        data: param
+      })
+    }
+
+    return axios({
+      url: _url,
+      method
     })
   }
 
@@ -172,7 +233,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')
     }
 
@@ -207,14 +267,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')
     }
 
@@ -671,7 +729,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
   }
@@ -858,8 +924,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