update 优化token失效后跳转登录页的逻辑
This commit is contained in:
+5
-1
@@ -6,7 +6,7 @@ import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
|||||||
import { useMessage } from '/@/hooks/web/useMessage.ts';
|
import { useMessage } from '/@/hooks/web/useMessage.ts';
|
||||||
import { checkStatus } from '/@/api/checkStatus.ts';
|
import { checkStatus } from '/@/api/checkStatus.ts';
|
||||||
import router from '/@/router';
|
import router from '/@/router';
|
||||||
import { getBaseLogin } from '/@/enum/pageEnum.ts';
|
import { getBaseLogin, toLoginByNowPath } from '/@/enum/pageEnum.ts';
|
||||||
|
|
||||||
const { createMessage, createErrorModal } = useMessage();
|
const { createMessage, createErrorModal } = useMessage();
|
||||||
const { VITE_GLOB_API_URL } = getAppEnvConfig();
|
const { VITE_GLOB_API_URL } = getAppEnvConfig();
|
||||||
@@ -34,6 +34,10 @@ service.interceptors.response.use(
|
|||||||
switch (error.response.data.code) {
|
switch (error.response.data.code) {
|
||||||
case 401:
|
case 401:
|
||||||
let path = getBaseLogin();
|
let path = getBaseLogin();
|
||||||
|
if (!path) {
|
||||||
|
path = toLoginByNowPath(router.currentRoute.value.path);
|
||||||
|
}
|
||||||
|
createMessage.warn(error.response.data.message);
|
||||||
router.replace({
|
router.replace({
|
||||||
path: path,
|
path: path,
|
||||||
});
|
});
|
||||||
|
|||||||
+15
-2
@@ -7,9 +7,22 @@ export enum PageEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setBaseLogin(baseLogin) {
|
export function setBaseLogin(baseLogin) {
|
||||||
sessionStorage.setItem('baseLogin', baseLogin);
|
localStorage.setItem('baseLogin', baseLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBaseLogin() {
|
export function getBaseLogin() {
|
||||||
return sessionStorage.getItem('baseLogin');
|
return localStorage.getItem('baseLogin');
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据当前路径跳转登录页
|
||||||
|
export function toLoginByNowPath(nowPath: string) {
|
||||||
|
//西安的页面路径
|
||||||
|
const xianPath = ['/home', '/secondScreen'];
|
||||||
|
//银川的页面路径
|
||||||
|
const yinchuanPath = ['/yinChuanHome'];
|
||||||
|
if (xianPath.includes(nowPath)) {
|
||||||
|
return PageEnum.BASE_LOGIN;
|
||||||
|
} else if (yinchuanPath.includes(nowPath)) {
|
||||||
|
return PageEnum.BASE_LOGIN_YINCHUAN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,9 @@
|
|||||||
function setList(data = {}) {
|
function setList(data = {}) {
|
||||||
list.value.forEach((item) => {
|
list.value.forEach((item) => {
|
||||||
const { key } = item;
|
const { key } = item;
|
||||||
item.value = data[key];
|
if (data && data.hasOwnProperty(key)) {
|
||||||
|
item.value = data[key];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user