From fb8db39ccdca6ca638b3e133d186cb3fe6a558bc Mon Sep 17 00:00:00 2001
From: Lou <luzhiping@qqyjz.com>
Date: Mon, 04 Mar 2024 17:43:08 +0800
Subject: [PATCH] 更新

---
 http/api.js |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/http/api.js b/http/api.js
index de859da..819d59c 100644
--- a/http/api.js
+++ b/http/api.js
@@ -26,6 +26,8 @@
 	}
 	if (accessToken) {
 		config.header['Blade-Auth'] = 'bearer ' + accessToken;
+		config.header['roleName'] = uni.getStorageSync("activeRole").roleAlias || "";
+		config.header['communityCode'] = uni.getStorageSync("siteInfo").id || ""
 	}
 	if (config.params.tenantId) {
 		config.header['Tenant-Id'] = config.params.tenantId;
@@ -67,15 +69,28 @@
 }, config => { // 可使用async await 做异步操作
 	return Promise.reject(config)
 })
+
+// uni.showLoading({
+// 	title:"加载中..."
+// })
+
 http.interceptors.response.use((response) => {
+
 	// 若有数据返回则通过
 	if (response.data.access_token || response.data.key) {
 		return response.data
 	}
-
 	// 服务端返回的状态码不等于200,则reject()
 	if (response.data.code) {
 		if (response.data.code !== 200) {
+			uni.showToast({
+				title: response.data.msg,
+				icon: 'none'
+			});
+			return Promise.reject(response);
+		}
+	} else {
+		if (response.data.error_code !== 200) {
 			uni.showToast({
 				title: response.data.msg,
 				icon: 'none'
@@ -86,7 +101,8 @@
 
 	//数据中台返回的数据结果
 	if (response.statusCode) {
-		if (response.statusCode !== 200) {
+		// uni.hideLoading()
+		if (response.statusCode >= 300) {
 			console.log(response.data.msg)
 			uni.showToast({
 				title: '系统繁忙,请稍后再试',
@@ -107,11 +123,15 @@
 		const currentPage = pages[pages.length - 1]
 		uni.setStorageSync("responIndex", 0)
 		uni.clearStorageSync()
+		// uni.redirectTo({
+		// 	url: `/pages/login/login-account?redirect=/${currentPage.route}`
+		// })
+
 
 		uni.showModal({
 			title: "提示",
 			content: "请登录",
-			showCancel: false,
+			// showCancel: false,
 			success: res => {
 				if (res.confirm) {
 					uni.redirectTo({
@@ -122,9 +142,11 @@
 				}
 			}
 		})
-
-
-
+	} else {
+		uni.showToast({
+			title: '系统繁忙,请稍后再试',
+			icon: 'none'
+		});
 	}
 	return Promise.reject(response)
 })

--
Gitblit v1.9.3