mirror of
http://36.133.248.69:3088/admin/RentWeAppFront.git
synced 2026-06-07 06:22:27 +08:00
继续修复白屏bug
This commit is contained in:
@@ -23,26 +23,48 @@ const install = (Vue, vm) => {
|
||||
return config;
|
||||
};
|
||||
// 响应拦截,判断状态码是否通过
|
||||
// 防止多次跳转登录页
|
||||
let isRedirectingToLogin = false;
|
||||
|
||||
Vue.prototype.$u.http.interceptor.response = (res) => {
|
||||
// 如果把originalData设置为了true,这里得到将会是服务器返回的所有的原始数据
|
||||
// 判断可能变成了res.statueCode,或者res.data.code之类的,请打印查看结果
|
||||
if(res.statusCode == 200) {
|
||||
return res.data;
|
||||
return res.data;
|
||||
} else if(res.statusCode == 301) {
|
||||
vm.$u.toast('警告:' + res.msg);
|
||||
return false;
|
||||
} else if(res.statusCode == 401 || res.statusCode == 403) {
|
||||
const currentPage = vm.$route.path;
|
||||
// 防止多次跳转
|
||||
if (isRedirectingToLogin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断当前页面是否为登录页
|
||||
// 登录成功修改token与用户信息
|
||||
vm.$u.vuex('vuex_token', '');
|
||||
vm.$u.vuex('vuex_user', {});
|
||||
uni.removeStorageSync('userInfo');
|
||||
if (currentPage !== '/pages-biz/login/login') {
|
||||
uni.navigateTo({
|
||||
url: '/pages-biz/login/login'
|
||||
});
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentPath = currentPage ? currentPage.route : '';
|
||||
|
||||
if (currentPath !== 'pages-biz/login/login') {
|
||||
isRedirectingToLogin = true;
|
||||
|
||||
// 清除 token 和用户信息
|
||||
vm.$u.vuex('vuex_token', '');
|
||||
vm.$u.vuex('vuex_user', {});
|
||||
uni.removeStorageSync('userInfo');
|
||||
|
||||
vm.$u.toast('认证失败,请重新登录');
|
||||
|
||||
// 使用 reLaunch 清空页面栈,避免返回时出现问题
|
||||
uni.reLaunch({
|
||||
url: '/pages-biz/login/login',
|
||||
complete: () => {
|
||||
// 跳转完成后重置标记
|
||||
setTimeout(() => {
|
||||
isRedirectingToLogin = false;
|
||||
}, 1000)
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
} else if(res.statusCode == 500) {
|
||||
|
||||
Reference in New Issue
Block a user