fix: 解决登录情况下,输入任意路由跳转到安全入口的问题 (#954)

This commit is contained in:
ssongliu 2023-05-09 15:45:47 +08:00 committed by GitHub
parent eea28e8481
commit 7d4a8782d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -13,6 +13,7 @@ export const checkStatus = (status: number, msg: string): void => {
MsgError(msg ? msg : i18n.global.t('commons.res.notFound')); MsgError(msg ? msg : i18n.global.t('commons.res.notFound'));
break; break;
case 403: case 403:
globalStore.setLogStatus(false);
router.replace({ name: 'entrance', params: { code: globalStore.entrance } }); router.replace({ name: 'entrance', params: { code: globalStore.entrance } });
MsgError(msg ? msg : i18n.global.t('commons.res.forbidden')); MsgError(msg ? msg : i18n.global.t('commons.res.forbidden'));
break; break;

View File

@ -42,6 +42,7 @@ class RequestHttp {
globalStore.setCsrfToken(response.headers['x-csrf-token']); globalStore.setCsrfToken(response.headers['x-csrf-token']);
} }
if (data.code == ResultEnum.OVERDUE || data.code == ResultEnum.FORBIDDEN) { if (data.code == ResultEnum.OVERDUE || data.code == ResultEnum.FORBIDDEN) {
globalStore.setLogStatus(false);
router.push({ router.push({
name: 'entrance', name: 'entrance',
params: { code: globalStore.entrance }, params: { code: globalStore.entrance },
@ -49,6 +50,7 @@ class RequestHttp {
return Promise.reject(data); return Promise.reject(data);
} }
if (data.code == ResultEnum.EXPIRED) { if (data.code == ResultEnum.EXPIRED) {
globalStore.setLogStatus(false);
router.push({ name: 'Expired' }); router.push({ name: 'Expired' });
return data; return data;
} }

View File

@ -11,10 +11,23 @@ const axiosCanceler = new AxiosCanceler();
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start(); NProgress.start();
axiosCanceler.removeAllPending(); axiosCanceler.removeAllPending();
const globalStore = GlobalStore();
if (to.name === 'entrance' && globalStore.isLogin) {
if (to.params.code === globalStore.entrance) {
next({
name: 'entrance',
params: { code: globalStore.entrance },
});
NProgress.done();
return;
}
next({ name: '404' });
NProgress.done();
return;
}
if (!to.matched.some((record) => record.meta.requiresAuth)) return next(); if (!to.matched.some((record) => record.meta.requiresAuth)) return next();
const globalStore = GlobalStore();
if (!globalStore.isLogin) { if (!globalStore.isLogin) {
next({ next({
name: 'entrance', name: 'entrance',
@ -23,6 +36,7 @@ router.beforeEach((to, from, next) => {
NProgress.done(); NProgress.done();
return; return;
} }
return next(); return next();
}); });