Commit f56450c6b7b1c367b3a4e7a1dd6f69a832f2de97
1 parent
f7268e7c
v3.8.1 修复登录失效后多次请求提示多次弹窗问题
Showing
1 changed file
with
22 additions
and
13 deletions
yudao-ui-admin/src/utils/request.js
| @@ -5,6 +5,9 @@ import { getToken } from '@/utils/auth' | @@ -5,6 +5,9 @@ import { getToken } from '@/utils/auth' | ||
| 5 | import errorCode from '@/utils/errorCode' | 5 | import errorCode from '@/utils/errorCode' |
| 6 | import Cookies from "js-cookie"; | 6 | import Cookies from "js-cookie"; |
| 7 | 7 | ||
| 8 | +// 是否显示重新登录 | ||
| 9 | +let isReloginShow; | ||
| 10 | + | ||
| 8 | axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' | 11 | axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
| 9 | // 创建axios实例 | 12 | // 创建axios实例 |
| 10 | const service = axios.create({ | 13 | const service = axios.create({ |
| @@ -60,19 +63,25 @@ service.interceptors.response.use(res => { | @@ -60,19 +63,25 @@ service.interceptors.response.use(res => { | ||
| 60 | // 获取错误信息 | 63 | // 获取错误信息 |
| 61 | const msg = errorCode[code] || res.data.msg || errorCode['default'] | 64 | const msg = errorCode[code] || res.data.msg || errorCode['default'] |
| 62 | if (code === 401) { | 65 | if (code === 401) { |
| 63 | - MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { | ||
| 64 | - confirmButtonText: '重新登录', | ||
| 65 | - cancelButtonText: '取消', | ||
| 66 | - type: 'warning' | ||
| 67 | - } | ||
| 68 | - ).then(() => { | ||
| 69 | - store.dispatch('LogOut').then(() => { | ||
| 70 | - // if (location.pathname !== '/login') { // 避免重复跳转 | ||
| 71 | - // | ||
| 72 | - // } | ||
| 73 | - location.href = '/index'; | ||
| 74 | - }) | ||
| 75 | - }).catch(() => {}); | 66 | + if (!isReloginShow) { |
| 67 | + isReloginShow = true; | ||
| 68 | + MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { | ||
| 69 | + confirmButtonText: '重新登录', | ||
| 70 | + cancelButtonText: '取消', | ||
| 71 | + type: 'warning' | ||
| 72 | + } | ||
| 73 | + ).then(() => { | ||
| 74 | + isReloginShow = false; | ||
| 75 | + store.dispatch('LogOut').then(() => { | ||
| 76 | + // 如果是登录页面不需要重新加载 | ||
| 77 | + if (window.location.hash.indexOf("#/login") !== 0) { | ||
| 78 | + location.href = '/index'; | ||
| 79 | + } | ||
| 80 | + }) | ||
| 81 | + }).catch(() => { | ||
| 82 | + isReloginShow = false; | ||
| 83 | + }); | ||
| 84 | + } | ||
| 76 | return Promise.reject('无效的会话,或者会话已过期,请重新登录。') | 85 | return Promise.reject('无效的会话,或者会话已过期,请重新登录。') |
| 77 | } else if (code === 500) { | 86 | } else if (code === 500) { |
| 78 | Message({ | 87 | Message({ |