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

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