diff --git a/src/utils/request.js b/src/utils/request.js index 3fdbcf5..867a63b 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -37,6 +37,8 @@ let timer = null let isRefreshing = false //重试队列 let requests = [] +// 在模块作用域定义一个全局标志变量 +let isHandlingTokenInvalid = false axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' // 创建axios实例 @@ -111,7 +113,6 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( (res) => { - console.log(res, '相应拦截器拦截内容') // 请求完成时清除唯一标识符 const requestIdentifier = `${res.config.url}-${res.config.method}` const index = requests.indexOf(requestIdentifier) @@ -133,37 +134,43 @@ service.interceptors.response.use( } if (code === '500') { - MessageBox.confirm(msg, '系统提示', { - confirmButtonText: '确定', - showCancelButton: false, - showClose: false, - closeOnClickModal: false, - closeOnPressEscape: false, - type: 'error' - }) - .then(() => { - console.log(res, '相应拦截器拦截内容') - if (msg === 'token无效') { + // 判断是否在处理 token 无效情况 + if (msg === 'token无效' && isHandlingTokenInvalid) return + if (msg === 'token无效' && !isHandlingTokenInvalid) { + isHandlingTokenInvalid = true; + MessageBox.confirm('token过期请重新登录!', '系统提示', { + confirmButtonText: '确定', + showCancelButton: false, + showClose: false, + closeOnClickModal: false, + closeOnPressEscape: false, + type: 'error' + }) + .then(() => { store.dispatch('LogOut').then(() => { route.replace({ path: '/login' - }) - - }) - } - if (res.config.headers.dj==='queryTreeById') { - store.dispatch('LogOut').then(() => { - route.replace({ - path: '/login' - }) - - }) - } - - }) - .catch(() => { - }) - return Promise.reject(new Error(msg)) + }); + // 重置标志变量 + isHandlingTokenInvalid = false; + }); + }) + .catch(() => { + // 处理取消逻辑 + isHandlingTokenInvalid = false; + }); + } else { + // 其他错误处理 + MessageBox.confirm(msg, '系统提示', { + confirmButtonText: '确定', + showCancelButton: false, + showClose: false, + closeOnClickModal: false, + closeOnPressEscape: false, + type: 'error' + }); + } + return Promise.reject(new Error(msg)); } else if (code == '1002') { MessageBox.confirm(msg, '系统提示', { diff --git a/src/views/applicationList/index.vue b/src/views/applicationList/index.vue index bca65ee..42e7fb8 100644 --- a/src/views/applicationList/index.vue +++ b/src/views/applicationList/index.vue @@ -16,7 +16,7 @@