diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 9a53489..6db56d6 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -80,22 +80,31 @@ const transform: AxiosTransform = { switch (code) { case ResultEnum.UNAUTHRAZATION: timeoutMsg = t('登录超时,请重新登录!'); + const userStore = useUserStoreWithOut(); userStore.setToken(undefined); if (!window.location.hash.includes('login')&&!window.location.pathname.includes('login') &&!window.location.hash.includes('tokenLogin')&&!window.location.pathname.includes('tokenLogin')) { userStore.logout(true); } - if(data.urlToRedirectTo){ - //登录页面不跳转 - if(!window.location.hash.includes('login')&&!window.location.pathname.includes('login') - &&!window.location.hash.includes('tokenLogin')&&!window.location.pathname.includes('tokenLogin')){ - window.location.href=data.urlToRedirectTo; + if (data) { + if(data.urlToRedirectTo){ + //登录页面不跳转 + if(!window.location.hash.includes('login')&&!window.location.pathname.includes('login') + &&!window.location.hash.includes('tokenLogin')&&!window.location.pathname.includes('tokenLogin')){ + window.location.href=data.urlToRedirectTo; + } + options.errorMessageMode="none"; + }else{ + // data 有logout 信息 ,存sessionStorage 给login page 弹框显示 + if (data.logoutMessage) { + sessionStorage.setItem('logoutInfoData', JSON.stringify({ + logoutMessage: data.logoutMessage, + })); + } + const go = useGo(); + go('/login'); } - options.errorMessageMode="none"; - }else{ - const go = useGo(); - go('/login'); } break; default: diff --git a/src/views/sys/login/Login.vue b/src/views/sys/login/Login.vue index 7c01d9c..42d7f38 100644 --- a/src/views/sys/login/Login.vue +++ b/src/views/sys/login/Login.vue @@ -42,9 +42,20 @@ import logopng from '/@/assets/images/logo-dark.png'; import logobg from '/@/assets/images/login-left.gif'; import { getLogoInfo } from '/@/api/system/login'; - import { ref } from 'vue'; + import { ref, onMounted } from 'vue'; import { LogoConfig } from '/#/config'; + import { useMessage } from '/@/hooks/web/useMessage'; + const { createErrorModal } = useMessage(); + + onMounted(() => { + let logoutInfoData = JSON.parse(sessionStorage.getItem('logoutInfoData') as string); + if (logoutInfoData) { + createErrorModal({ title: t('错误提示'), content: logoutInfoData.logoutMessage }); + sessionStorage.removeItem('logoutInfoData'); + } + }) + const appStore = useAppStore(); defineProps({ sessionTimeout: {