From c34207ce5511f647d9ee78c97e8a2c26738cee56 Mon Sep 17 00:00:00 2001
From: xuxueyang <xuxy@fengyuntec.com>
Date: 星期四, 12 九月 2024 16:08:48 +0800
Subject: [PATCH] 1
---
plugins/http.js | 39 +++++++++++++++++++++++----------------
1 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/plugins/http.js b/plugins/http.js
index bd19a45..083f90c 100644
--- a/plugins/http.js
+++ b/plugins/http.js
@@ -1,7 +1,7 @@
import environments from '@/environments'
import message from './message'
import storage from './storage'
-// import store from '../store'
+import store from '../store'
import utils from './util.js'
// import Vue from 'vue'
// import {
@@ -52,7 +52,8 @@
dataType: options.dataType ? options.dataType : 'json',
data: options.data || null,
header,
- success: (res) => {
+ timeout: 30000,
+ success: async (res) => {
if (!options.ignore) {
message.hideLoading()
}
@@ -87,13 +88,13 @@
validmsg = res.data.msg
message.showToast(res.data.data)
}
- if(validmsg){
+ if (validmsg) {
//兼容安卓手机提醒过快问题
setTimeout(() => {
message.showToast(validmsg)
}, 200)
}
-
+
reject({
@@ -107,13 +108,10 @@
} else if (res.data.code === '401' || res.data && res.data.code &&
res.data.code.startsWith('401')) {
console.log('resp', res)
+ // storage.removeItem('token')
+ await store.dispatch('logout')
message.showToast('登录信息失效')
- storage.removeItem('token')
- reject({
- data: null,
- code: 401,
- msg: 'Unauthorized'
- })
+
// #ifdef PUB_CUSTOMER
uni.reLaunch({
url: '/pages/user/supplier-user'
@@ -124,6 +122,11 @@
url: '/pages/login/supplier-login'
})
// #endif
+ reject({
+ data: null,
+ code: 401,
+ msg: 'Unauthorized'
+ })
} else {
if (res.data.data && typeof res.data.data === 'string') {
@@ -148,13 +151,11 @@
// commit('updat')
// store.commit('updateLogin', false)
console.log('401', res)
- message.showToast('登录信息失效')
storage.removeItem('token')
- reject({
- data: null,
- code: 401,
- msg: 'Unauthorized'
- })
+ await store.dispatch('logout')
+ message.showToast('登录信息失效')
+
+
// #ifdef PUB_CUSTOMER
uni.reLaunch({
url: '/pages/user/supplier-user'
@@ -165,6 +166,11 @@
url: '/pages/login/supplier-login'
})
// #endif
+ reject({
+ data: null,
+ code: 401,
+ msg: 'Unauthorized'
+ })
} else if (res.statusCode === 403) {
message.showToast('请求被拒绝')
@@ -214,6 +220,7 @@
if (!options.ignore) {
message.hideLoading()
}
+ message.showToast('网络异常')
reject({
data: null,
code: 9999,
--
Gitblit v1.9.3