From 59274dabbf6a7ac4b5a77d9527d47d94e9a62d77 Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Wed, 22 Feb 2023 06:33:40 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9http=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=EF=BC=8C=E5=AF=B9801=E7=8A=B6=E6=80=81=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E8=BF=9B=E8=A1=8C=E7=BB=AD=E7=AD=BE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dong Xia --- src/utils/request.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index ce1550b..bb68166 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -108,11 +108,9 @@ request.interceptors.response.use( // for debug return Promise.reject(error) } - // 如果 headers 里面配置了 loading: no 就不用 loading if (!error.response.config.headers[NO_LOADING_KEY]) { $global_loading && $global_loading.close() } - // 如果 headers 里面配置了 tip: no 就不用弹出提示信息 if (!error.response.config.headers[NO_NOTIFY_KEY]) { const { status, statusText, data } = error.response if (!status) { @@ -133,10 +131,9 @@ request.interceptors.response.use( } ) -// 判断 jwt token 状态 function checkJWTToken(res, response) { // 如果是登录信息失效 - if (res.code === 800) { + if (res.code === 800 || res.code === 801) { notification.warn({ message: res.msg, // description: response.config.url, @@ -148,31 +145,18 @@ function checkJWTToken(res, response) { }) return false } - // 如果 jwt token 还可以续签 - if (res.code === 801) { - notification.close() - notification.info({ - message: '登录信息过期,尝试自动续签...', - description: '如果不需要自动续签,请修改配置文件。该续签将不会影响页面。', - duration: 3 - }) - // 续签且重试请求 - return redoRequest(response.config) - } + } -// 刷新 jwt token 并且重试上次请求 function redoRequest(config) { return new Promise((resolve) => { Promise.resolve(refreshToken()).then((result) => { if (result.code === 200) { - // 调用 store action 存储当前登录的用户名和 token store.dispatch('login', result.data) resolve() } }) }).then(() => { - // 重试原来的请求 return request(config) }) } -- Gitee