diff --git a/src/utils/request.js b/src/utils/request.js index ce1550b52404fa826b0e78a050be68dc1281c486..bb681664c24e8332678f5edc5a9eed072e96cda1 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) }) }