Browse Source

no message

linwenxin 1 month ago
parent
commit
420eb0a55b
1 changed files with 25 additions and 0 deletions
  1. 25 0
      src/common/http/index.js

+ 25 - 0
src/common/http/index.js

@@ -7,6 +7,25 @@ import { goLoginPage } from '@/mixins/index.js'
 
 import { setStorage, getStorage, removeStorage } from '@/common/utils/storage.js'
 import { navToPage } from 'common/utils/navPag'
+// #ifdef H5
+// 解析地址栏参数
+function getQueryVariable(variable) {
+  // 从?开始获取后面的所有数据
+  var query = window.location.search.substring(1)
+  // 从字符串&开始分隔成数组split
+  var vars = query.split('&')
+  // 遍历该数组
+  for (var i = 0; i < vars.length; i++) {
+    // 从等号部分分割成字符
+    var pair = vars[i].split('=')
+    // 如果第一个元素等于 传进来的参的话 就输出第二个元素
+    if (pair[0] == variable) {
+      return pair[1]
+    }
+  }
+  return undefined
+}
+// #endif
 
 const program = {
   H5: 'wap',
@@ -73,6 +92,9 @@ export const $http = (url, method, data, json, loadingBool = false, isExecute =
         return Promise.reject(new Error(res.message || 'Error'))
       }
       if (res.code === 4444) {
+        // #ifdef H5
+        uni.removeStorageSync(`APPID${getQueryVariable('appid')}_token`)
+        // #endif
         removeQueryParams(['x-token'])
         return {}
       }
@@ -284,6 +306,9 @@ export const axios = function (obj = {}) {
           }
 
           if (res.code === 4444) {
+            // #ifdef H5
+            uni.removeStorageSync(`APPID${getQueryVariable('appid')}_token`)
+            // #endif
             removeQueryParams(['x-token'])
             reject(new Error(res.message || 'Error'))
             return {}