优化某些情况下登录权限问题

master
paulGao 2022-07-06 16:22:46 +08:00 committed by 学习很差啦
parent b840a0adf1
commit ba02c6ca7d
1 changed files with 23 additions and 24 deletions

View File

@ -28,8 +28,8 @@ function cleanStorage() {
storage.setUserInfo({});
if(!isNavigateTo){
isNavigateTo= true
if (!isNavigateTo) {
isNavigateTo = true
// 防抖处理跳转
// #ifdef MP-WEIXIN
uni.navigateTo({
@ -112,14 +112,14 @@ http.interceptors.response.use(
// cleanStorage();
// isRefreshing = false;
// }
console.log(response)
let token = storage.getAccessToken();
if (
(token && response.statusCode === 403) ||
response.data.status === 403
) {
if (!isRefreshing) {
console.log('旧token',token)
console.log('旧token', token)
isRefreshing = true;
let oldRefreshToken = storage.getRefreshToken();
//调用刷新token的接口
@ -131,13 +131,13 @@ http.interceptors.response.use(
response.header.accessToken = `${accessToken}`;
// token 刷新后将数组的方法重新执行
console.log('接口队列',requests,'新token',accessToken)
// console.log('接口队列', requests, '新token', accessToken)
requests.forEach((cb) => cb(accessToken));
requests = []; // 重新请求完清空
return http.request(response.config);
})
.catch((err) => {
console.log('刷新token报错'+oldRefreshToken,err)
console.log('刷新token报错' + oldRefreshToken, err)
cleanStorage();
return Promise.reject(err);
})
@ -154,13 +154,12 @@ http.interceptors.response.use(
});
});
}
// 如果当前返回没登录
} else if (
(!token && !storage.getRefreshToken() && response.statusCode === 403) ||
response.data.code === 403
response.data.code === 403 || response.data.code === 20004
) {
console.log('没有token 以及刷新token 内容',token,storage.getRefreshToken())
// console.log('没有token 以及刷新token 内容', token, storage.getRefreshToken())
cleanStorage();
// 如果当前状态码为正常但是success为不正常时