From 58b41dc039c5c9d1b758c9e190a7c35225ad7585 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期四, 05 三月 2026 18:04:25 +0800
Subject: [PATCH] #

---
 config/request.js |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/config/request.js b/config/request.js
index 9a8beab..3f99929 100644
--- a/config/request.js
+++ b/config/request.js
@@ -9,7 +9,7 @@
 			settings = {
 				ip: '127.0.0.1',
 				port: '8080',
-				project: 'jshdasrs'
+				project: 'wms'
 			};
 			// uni.setStorageSync('app_settings', settings);
 		}
@@ -25,6 +25,18 @@
 		// 鍒濆鍖栬姹傛嫤鎴櫒鏃讹紝浼氭墽琛屾鏂规硶锛屾鏃禿ata涓簎ndefined锛岃祴浜堥粯璁}
 		config.data = config.data || {}
 
+		// 鍔ㄦ�佽幏鍙栬缃紝鏀寔鍦ㄨ繍琛屾椂淇敼 app_settings 鏃犻渶閲嶅惎
+		let settings = uni.getStorageSync('app_settings');
+		if (!settings) {
+			settings = {
+				ip: '127.0.0.1',
+				port: '8080',
+				project: 'wms'
+			};
+		}
+		// 閲嶅啓鎷︽埅鍣ㄧ殑 baseURL锛屾瘡娆¤姹傞兘鐢熸晥
+		config.baseURL = `http://${settings.ip}:${settings.port}/${settings.project}`;
+
 		// 鎻愮ず鍔犺浇妗嗛�昏緫锛堟牴鎹� custom.hideLoading 鍐冲畾锛�
 		const hideLoading = config.custom?.hideLoading;
 		if (hideLoading === false || hideLoading === undefined) {
@@ -34,13 +46,9 @@
 			});
 		}
 
-		// 鏍规嵁custom鍙傛暟涓厤缃殑鏄惁闇�瑕乼oken锛屾坊鍔犲搴旂殑璇锋眰澶�
-		// 榛樿鎴栨樉寮� auth 涓� true 鏃舵坊鍔� token
-		if (config?.custom?.auth !== false) {
-			const token = uni.getStorageSync('token');
-			if (token) {
-				config.header.token = token;
-			}
+		const token = uni.getStorageSync('token');
+		if (token) {
+			config.header.token = token;
 		}
 		return config
 	}, config => { // 鍙娇鐢╝sync await 鍋氬紓姝ユ搷浣�
@@ -60,9 +68,16 @@
 		const custom = response.config?.custom || {}
 
 		if (data.code !== 200) {
-			// 濡傛灉娌℃湁鏄惧紡瀹氫箟custom鐨則oast鍙傛暟涓篺alse鐨勮瘽锛岄粯璁ゅ鎶ラ敊杩涜toast寮瑰嚭鎻愮ず
-			if (custom.toast !== false) {
-				uni.$u.toast(data.msg || data.message || '璇锋眰澶辫触')
+			if (data.code === 401 || data.code === 403) {
+				vm.$showToast({ type: 'error', message: data.msg || data.message || '璇烽噸鏂扮櫥褰�' })
+				setTimeout(() => {
+					uni.reLaunch({ url: '/pages/login/login' })
+				}, 1000)
+			} else {
+				// 濡傛灉娌℃湁鏄惧紡瀹氫箟custom鐨則oast鍙傛暟涓篺alse鐨勮瘽锛岄粯璁ゅ鎶ラ敊杩涜toast寮瑰嚭鎻愮ず
+				if (custom.toast !== false) {
+					vm.$showToast({ type: 'error', message: data.msg || data.message || '璇锋眰澶辫触' })
+				}
 			}
 
 			// 濡傛灉闇�瑕乧atch杩斿洖锛屽垯杩涜reject
@@ -70,7 +85,7 @@
 				return Promise.reject(data)
 			} else {
 				// 鍚﹀垯杩斿洖涓�涓猵ending涓殑promise锛岃姹備笉浼氳繘鍏atch涓�
-				return new Promise(() => {})
+				return new Promise(() => { })
 			}
 		}
 		// 鏍规嵁绀轰緥锛岃繑鍥炰笟鍔℃暟鎹�
@@ -81,6 +96,17 @@
 		if (hideLoading === false || hideLoading === undefined) {
 			uni.hideLoading();
 		}
+
+		if (response.statusCode === 401 || response.statusCode === 403) {
+			vm.$showToast({ type: 'error', message: '璇烽噸鏂扮櫥褰�' })
+			setTimeout(() => {
+				uni.reLaunch({ url: '/pages/login/login' })
+			}, 1000)
+		} else {
+			const errMsg = response.data?.msg || response.data?.message || '璇锋眰澶辫触';
+			vm.$showToast({ type: 'error', message: errMsg })
+		}
+
 		return Promise.reject(response)
 	})
 }
\ No newline at end of file

--
Gitblit v1.9.1