From f56450c6b7b1c367b3a4e7a1dd6f69a832f2de97 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Feb 2022 19:05:06 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.1=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E5=90=8E=E5=A4=9A=E6=AC=A1=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=A4=9A=E6=AC=A1=E5=BC=B9=E7=AA=97=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/utils/request.js | 35 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/yudao-ui-admin/src/utils/request.js b/yudao-ui-admin/src/utils/request.js index 315b9ae8b..76b1df1d1 100644 --- a/yudao-ui-admin/src/utils/request.js +++ b/yudao-ui-admin/src/utils/request.js @@ -5,6 +5,9 @@ import { getToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' import Cookies from "js-cookie"; +// 是否显示重新登录 +let isReloginShow; + axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' // 创建axios实例 const service = axios.create({ @@ -60,19 +63,25 @@ service.interceptors.response.use(res => { // 获取错误信息 const msg = errorCode[code] || res.data.msg || errorCode['default'] if (code === 401) { - MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { - confirmButtonText: '重新登录', - cancelButtonText: '取消', - type: 'warning' - } - ).then(() => { - store.dispatch('LogOut').then(() => { - // if (location.pathname !== '/login') { // 避免重复跳转 - // - // } - location.href = '/index'; - }) - }).catch(() => {}); + if (!isReloginShow) { + isReloginShow = true; + MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { + confirmButtonText: '重新登录', + cancelButtonText: '取消', + type: 'warning' + } + ).then(() => { + isReloginShow = false; + store.dispatch('LogOut').then(() => { + // 如果是登录页面不需要重新加载 + if (window.location.hash.indexOf("#/login") !== 0) { + location.href = '/index'; + } + }) + }).catch(() => { + isReloginShow = false; + }); + } return Promise.reject('无效的会话,或者会话已过期,请重新登录。') } else if (code === 500) { Message({