From 09a4dffa44acc386ab66b4e01af473068586e4fb Mon Sep 17 00:00:00 2001
From: Mr.Shi <1878285526@qq.com>
Date: 星期一, 04 九月 2023 10:38:55 +0800
Subject: [PATCH] 小程序
---
minipro_standard/util/request/responseInterceptors.js | 47 ++++++++++++++++++++++++++++++-----------------
1 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/minipro_standard/util/request/responseInterceptors.js b/minipro_standard/util/request/responseInterceptors.js
index a88ed54..16f08d8 100644
--- a/minipro_standard/util/request/responseInterceptors.js
+++ b/minipro_standard/util/request/responseInterceptors.js
@@ -4,25 +4,38 @@
*/
module.exports = (vm) => {
uni.$u.http.interceptors.response.use((response) => {
- /* 瀵瑰搷搴旀垚鍔熷仛鐐逛粈涔� 鍙娇鐢╝sync await 鍋氬紓姝ユ搷浣�*/
+ uni.hideLoading();
const data = response.data
- // 鑷畾涔夊弬鏁�
- // const custom = response.config?.custom
- // if (data.code !== 200) { // 鏈嶅姟绔繑鍥炵殑鐘舵�佺爜涓嶇瓑浜�200锛屽垯reject()
- // uni.$u.toast(data.message)
- // if (data.code === 401) {
- // // console.log('鏈櫥褰曘�佺櫥褰曞け鏁�');
- // // 鏈櫥褰曘�佺櫥褰曞け鏁�
- // uni.reLaunch({
- // url: '/pages/login/login'
- // })
- // }
- // return Promise.reject(data)
- // }
- // console.log(data.data);
- return data.data || {}
+ if (response.data.code === 401) { // 澶勭悊鐧诲綍杩囨湡
+ uni.showToast({ title: '鐧诲綍杩囨湡锛屽噯澶囪嚜鍔ㄩ噸鏂扮櫥褰�', icon: 'none', duration: 2000, mask: true });
+ setTimeout(() => {
+ uni.reLaunch({ url: '/pages/login/login' });
+ }, 2000)
+ return
+ }
+ if (response.data.code !== 200) { // 璇锋眰鎶ラ敊
+ uni.showToast({ title: response.data.message, icon: 'none', duration: 2000 });
+ }
+ return data || {}
}, (response) => {
- /* 瀵瑰搷搴旈敊璇仛鐐逛粈涔� 锛坰tatusCode !== 200锛�*/
+ uni.hideLoading();
+ let code;
+ if (error.code === "ECONNABORTED") {
+ code = 999
+ } else {
+ code = error.response.status
+ }
+ switch (code) {
+ case 404:
+ uni.showToast({ title: '璇锋眰璧勬簮涓嶅瓨鍦�', icon: 'none', duration: 2000 });
+ break;
+ case 500:
+ uni.showToast({ title: '鏈嶅姟鍣ㄨ祫婧愰敊璇�', icon: 'none', duration: 2000 });
+ break;
+ case 999:
+ uni.showToast({ title: '璇锋眰瓒呮椂', icon: 'none', duration: 2000 });
+ break;
+ }
return Promise.reject(response)
})
}
--
Gitblit v1.9.3