From ba02c6ca7d5db4c6c00b7e5b777d74771afa822a Mon Sep 17 00:00:00 2001 From: paulGao Date: Wed, 6 Jul 2022 16:22:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=90=E4=BA=9B=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E7=99=BB=E5=BD=95=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/request.js | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/utils/request.js b/utils/request.js index 3cb42cc..a05d24e 100644 --- a/utils/request.js +++ b/utils/request.js @@ -27,20 +27,20 @@ function cleanStorage() { storage.setUuid(""); storage.setUserInfo({}); - - if(!isNavigateTo){ - isNavigateTo= true - // 防抖处理跳转 - // #ifdef MP-WEIXIN - uni.navigateTo({ - url: "/pages/passport/wechatMPLogin", - }); - // #endif - // #ifndef MP-WEIXIN - uni.navigateTo({ - url: "/pages/passport/login", - }); - // #endif + + if (!isNavigateTo) { + isNavigateTo = true + // 防抖处理跳转 + // #ifdef MP-WEIXIN + uni.navigateTo({ + url: "/pages/passport/wechatMPLogin", + }); + // #endif + // #ifndef MP-WEIXIN + uni.navigateTo({ + url: "/pages/passport/login", + }); + // #endif } } @@ -84,7 +84,7 @@ http.interceptors.request.use( config.params = params; config.header.accessToken = accessToken; - + } config.header = { ...config.header, @@ -105,23 +105,23 @@ let requests = []; // 必须使用异步函数,注意 http.interceptors.response.use( async (response) => { - isNavigateTo = false + isNavigateTo = false /* 请求之后拦截器。可以使用async await 做异步操作 */ // token存在并且token过期 // if (isRefreshing && response.statusCode === 403) { // 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(); + let oldRefreshToken = storage.getRefreshToken(); //调用刷新token的接口 return refreshTokenFn(oldRefreshToken) .then((res) => { @@ -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为不正常时