From 2d43a1df3f5ba42710e6d21c27d1e13bdb8dfd56 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期一, 24 三月 2025 09:23:08 +0800
Subject: [PATCH] -
---
src/common/request/request.js | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/common/request/request.js b/src/common/request/request.js
index 7833e73..f2dfe5d 100644
--- a/src/common/request/request.js
+++ b/src/common/request/request.js
@@ -1,12 +1,13 @@
-锘�
// 寮曞叆luch-request
-import { http } from '@/uni_modules/uview-plus'
+import {
+ http
+} from '@/uni_modules/uview-plus'
import {
apiBaseUrl
} from '@/common/setting/constVarsHelper.js';
import * as db from '@/common/utils/dbHelper.js' //寮曞叆common
// 鍒濆鍖栬姹傞厤缃�
-const initRequest=(vm)=>{
+const initRequest = (vm) => {
http.setConfig((defaultConfig) => {
/* defaultConfig 涓洪粯璁ゅ叏灞�閰嶇疆 */
defaultConfig.baseURL = apiBaseUrl; /* 鏍瑰煙鍚� */
@@ -52,16 +53,15 @@
// 鑾峰彇鐢ㄦ埛token
const userToken = db.get("userToken");
if (!userToken) {
- //console.log("寮�鍚脊绐�");
- vm.$store.commit('showLoginTip', true);
+ console.log("寮�鍚脊绐�",vm.$store);
+ // vm.$store.commit('showLoginTip', true);
//console.log("寮圭獥宸茬粡寮�鍚�");
// return false;
} else {
config.header.Authorization = 'Bearer ' + userToken;
}
-
+ console.log(config, config?.custom?.needToken, 'config?.custom?.needToken');
}
-
//棰濆闇�姹�
if (config.custom.methodName == 'user.share' || config.custom.methodName == "pages.getpageconfig" ||
config.custom.methodName == "goods.goodsList") {
@@ -77,7 +77,7 @@
// 鍝嶅簲鎷︽埅
http.interceptors.response.use((response) => {
/* 瀵瑰搷搴旀垚鍔熷仛鐐逛粈涔� 鍙娇鐢╝sync await 鍋氬紓姝ユ搷浣�*/
- //console.log(response);
+ console.log(response,'response,');
const data = response.data
if (response.statusCode == 200) {
let pages = getCurrentPages();
@@ -85,7 +85,7 @@
if (!data.status && page) {
// 鐧诲綍淇℃伅杩囨湡鎴栬�呮湭鐧诲綍
- if (data.data === 14007 || data.data === 14006) {
+ if (data.data === 401 || data.data === 14006) {
// #ifdef APP-PLUS || APP-PLUS-NVUE
if (page.route.indexOf('pages/login/index') < 0) {
db.del("userToken");
@@ -107,12 +107,28 @@
// #endif
// #ifdef MP-WEIXIN || MP-ALIPAY || MP-TOUTIAO
db.del("userToken");
- vm.$store.commit('userInfo', null);
+ // vm.$store.commit('userInfo', null);
//console.log("寮�鍚櫥褰曞脊绐�");
- vm.$store.commit('hasLogin', false);
+ // vm.$store.commit('hasLogin', false);
// #endif
}
}
+ }else if(response.statusCode==401){
+ db.del("userToken");
+ uni.showToast({
+ title: '鐧诲綍澶辨晥锛岃閲嶆柊鐧诲綍锛�',
+ icon: 'none',
+ duration: 1000,
+ complete: function() {
+ setTimeout(function() {
+ uni.hideToast();
+ uni.redirectTo({
+ url: '/pages/login/index'
+ });
+ },
+ 1000);
+ }
+ });
}
return data === undefined ? {} : data
}, (response) => {
@@ -124,8 +140,4 @@
}
export {
initRequest
-}
-
-
-
-
+}
\ No newline at end of file
--
Gitblit v1.9.1