This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { BASE_URL } from './env.js';
|
||||
import { useUserStore } from '@/store/user.js';
|
||||
|
||||
const showErrorToast = (message) => {
|
||||
uni.showToast({
|
||||
@@ -26,12 +27,14 @@ const request = (options) => {
|
||||
const { code, msg, data } = responseData;
|
||||
|
||||
if (res.statusCode === 401) {
|
||||
uni.removeStorageSync('token');
|
||||
uni.removeStorageSync('identifier');
|
||||
showErrorToast(msg || '登录已过期,请重新登录');
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
}, 2000);
|
||||
// A late response from an old login must not clear a new session.
|
||||
if (token === (uni.getStorageSync('token') || '')) {
|
||||
useUserStore().clearUser();
|
||||
showErrorToast(msg || responseData.message || '登录已过期,请重新登录');
|
||||
setTimeout(() => {
|
||||
if (!uni.getStorageSync('token')) uni.reLaunch({ url: '/pages/login/login' });
|
||||
}, 2000);
|
||||
}
|
||||
reject(responseData);
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +45,7 @@ const request = (options) => {
|
||||
}
|
||||
|
||||
if (options.showError !== false) {
|
||||
showErrorToast(msg);
|
||||
showErrorToast(msg || responseData.message);
|
||||
}
|
||||
reject(responseData);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user