From 4b18ab4bf4eff4383bd85beb76564dc6aeb1df86 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 26 一月 2021 19:11:26 +0800
Subject: [PATCH] 2021-01-26

---
 src/api/index.js |  112 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 99 insertions(+), 13 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index b6024f5..e260816 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -41,13 +41,11 @@
 axios.defaults.withCredentials = true
 
 axios.interceptors.request.use((config) => {
-  config.method = 'post'
   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')) {
     config.headers = { 'Content-Type': 'multipart/form-data' }
-  } else {
-    // config.headers.token = sessionStorage.getItem('TOKEN') || ''
+  } else if (config.method === 'post') {
     config.data = JSON.stringify(config.data)
   }
 
@@ -70,8 +68,6 @@
   }
 }
 
-window.GLOB.CacheMap = new Map()
-
 axios.interceptors.response.use((response) => {
   if (response.data.ErrCode === 'LoginError') {
     if (window.debugger === true) {
@@ -84,14 +80,16 @@
     return Promise.resolve(response.data)
   }
 }, (error) => {
-  notification.error({
-    className: 'notification-custom-error',
-    bottom: 0,
-    message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�',
-    placement: 'bottomRight',
-    duration: 15
-  })
-  return Promise.reject(error)
+  if (error && error.response) {
+    notification.error({
+      className: 'notification-custom-error',
+      bottom: 0,
+      message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�',
+      placement: 'bottomRight',
+      duration: 15
+    })
+  }
+  return Promise.reject(error.response)
 })
 
 class Api {
@@ -112,8 +110,33 @@
 
     return axios({
       url: '/webapi/dostar',
+      method: 'post',
       data: param
     })
+  }
+
+  /**
+   * @description 鐩存帴璇锋眰
+   * @param {Object} param 鏌ヨ鍙婃彁浜ゅ弬鏁�
+   */
+  directRequest (url, method = 'post', param) {
+    let params = { method: 'post' }
+    let _url = url
+
+    if (method === 'get' && param) {
+      let keys = Object.keys(param).map(key => `${key}=${param[key]}`)
+      keys = keys.join('&')
+      if (keys) {
+        _url = _url + '?' + keys
+      }
+    } else if (method === 'post' && param) {
+      params.data = param
+    }
+
+    _url = window.btoa(_url)
+    params.url = '/trans/redirect?rd=' + _url + '&method=' + method
+
+    return axios(params)
   }
 
   /**
@@ -128,6 +151,7 @@
 
     return axios({
       url: '/webapi/dostar',
+      method: 'post',
       data: param
     })
   }
@@ -161,6 +185,7 @@
 
     return axios({
       url: '/webapi/dologon',
+      method: 'post',
       data: param
     })
   }
@@ -192,6 +217,7 @@
 
     return axios({
       url: '/webapi/dologon',
+      method: 'post',
       data: param
     })
   }
@@ -222,6 +248,7 @@
 
     return axios({
       url: '/webapi/dologon',
+      method: 'post',
       data: param
     })
   }
@@ -284,6 +311,7 @@
       return new Promise((resolve, reject) => {
         axios({
           url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+          method: 'post',
           data: param
         }).then(res => {
           if (!res.status) {
@@ -414,6 +442,7 @@
 
     return axios({
       url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+      method: 'post',
       data: param
     })
   }
@@ -454,6 +483,7 @@
       return new Promise(resolve => {
         axios({
           url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+          method: 'post',
           data: param
         }).then(res => {
           if (res.status) {
@@ -487,6 +517,7 @@
 
     return axios({
       url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+      method: 'post',
       data: param
     })
   }
@@ -505,6 +536,7 @@
 
     return axios({
       url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+      method: 'post',
       data: param
     })
   }
@@ -558,6 +590,7 @@
             } else {
               axios({
                 url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+                method: 'post',
                 data: param
               }).then(res => {
                 if (res.status) {
@@ -572,6 +605,7 @@
 
             axios({
               url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+              method: 'post',
               data: param
             }).then(res => {
               if (res.status) {
@@ -590,6 +624,7 @@
       return new Promise(resolve => {
         axios({
           url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+          method: 'post',
           data: param
         }).then(res => {
           if (res.status) {
@@ -598,6 +633,46 @@
           resolve(res)
         })
       })
+    }
+  }
+
+  /**
+   * @description 鑾峰彇鏈湴绯荤粺閰嶇疆
+   * @param {Object}  param   璇锋眰鍙傛暟
+   */
+  getLocalCacheConfig (param) {
+    param.userid = sessionStorage.getItem('UserID') || ''
+    param.lang = localStorage.getItem('lang') || ''
+    param.SessionUid = localStorage.getItem('SessionUid') || ''
+    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
+    param.appkey = window.GLOB.appkey || ''
+
+    if (window.GLOB.mainSystemApi) {
+      param.rduri = window.GLOB.mainSystemApi
+    }
+
+    let _param  = md5(JSON.stringify(param))
+    
+    if (mkDataBase) {
+      return new Promise(resolve => {
+        mkDataBase.transaction(tx => {
+          tx.executeSql(`SELECT * FROM CONFIGS WHERE menuid='${param.MenuID}' and userid='${param.userid}'`, [], (tx, results) => {
+            let paramItem = results.rows[0]
+            if (paramItem) {
+              resolve({ ErrCode: 'S', ErrMesg: '', LongParam: paramItem.LongParam, message: '', status: true })
+            } else {
+              resolve({ ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false })
+            }
+          }, (tx, results) => {
+            mkDataBase = null
+            resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false})
+          })
+        })
+      })
+    } else if (window.GLOB.CacheMap.has(_param)) {
+      return Promise.resolve(window.GLOB.CacheMap.get(_param))
+    } else {
+      return Promise.resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false})
     }
   }
 
@@ -662,6 +737,7 @@
       return new Promise(resolve => {
         axios({
           url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+          method: 'post',
           data: param
         }).then(res => {
           if (res.status) {
@@ -692,6 +768,7 @@
 
     return axios({
       url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
+      method: 'post',
       data: param
     })
   }
@@ -710,6 +787,7 @@
       axios({
         url: '/webapi/doexcel',
         responseType: 'blob',
+        method: 'post',
         data: param
       }).then(res => {
 
@@ -781,11 +859,13 @@
 
       return axios({
         url: '/webapi/dostars',
+        method: 'post',
         data: param
       })
     } else {
       return axios({
         url: '/webapi/SaveBase64Image',
+        method: 'post',
         data: param
       })
     }
@@ -797,6 +877,7 @@
   getLargeFileUpload (param) {
     return axios({
       url: '/webapi/doupload',
+      method: 'post',
       data: param
     })
   }
@@ -807,6 +888,7 @@
   getFilePreUpload (param) {
     return axios({
       url: '/webapi/dopreload',
+      method: 'post',
       data: param
     })
   }
@@ -817,6 +899,7 @@
   getWxNativePay (param) {
     return axios({
       url: '/wxpay/wxNativePay',
+      method: 'post',
       data: param
     })
   }
@@ -827,6 +910,7 @@
   getFileUpload (param) {
     return axios({
       url: '/zh-CN/Home/Upload',
+      method: 'post',
       data: param
     })
   }
@@ -845,6 +929,7 @@
     
     return axios({
       url: '/webapi/dostar',
+      method: 'post',
       data: param
     })
   }
@@ -861,6 +946,7 @@
 
     return axios({
       url: '/webapi/dostar',
+      method: 'post',
       data: param
     })
   }

--
Gitblit v1.8.0