From 7d4a8782d83fa2e5944f5fe4087245d53eae1304 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 9 May 2023 15:45:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E8=BE=93=E5=85=A5=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC=E5=88=B0=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E5=85=A5=E5=8F=A3=E7=9A=84=E9=97=AE=E9=A2=98=20(#954)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/helper/check-status.ts | 1 + frontend/src/api/index.ts | 2 ++ frontend/src/routers/index.ts | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/src/api/helper/check-status.ts b/frontend/src/api/helper/check-status.ts index d05950b3c..1c18cc2a3 100644 --- a/frontend/src/api/helper/check-status.ts +++ b/frontend/src/api/helper/check-status.ts @@ -13,6 +13,7 @@ export const checkStatus = (status: number, msg: string): void => { MsgError(msg ? msg : i18n.global.t('commons.res.notFound')); break; case 403: + globalStore.setLogStatus(false); router.replace({ name: 'entrance', params: { code: globalStore.entrance } }); MsgError(msg ? msg : i18n.global.t('commons.res.forbidden')); break; diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index fd58611ee..2629a98e3 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -42,6 +42,7 @@ class RequestHttp { globalStore.setCsrfToken(response.headers['x-csrf-token']); } if (data.code == ResultEnum.OVERDUE || data.code == ResultEnum.FORBIDDEN) { + globalStore.setLogStatus(false); router.push({ name: 'entrance', params: { code: globalStore.entrance }, @@ -49,6 +50,7 @@ class RequestHttp { return Promise.reject(data); } if (data.code == ResultEnum.EXPIRED) { + globalStore.setLogStatus(false); router.push({ name: 'Expired' }); return data; } diff --git a/frontend/src/routers/index.ts b/frontend/src/routers/index.ts index 762200c2b..72e04a2ec 100644 --- a/frontend/src/routers/index.ts +++ b/frontend/src/routers/index.ts @@ -11,10 +11,23 @@ const axiosCanceler = new AxiosCanceler(); router.beforeEach((to, from, next) => { NProgress.start(); 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(); - - const globalStore = GlobalStore(); if (!globalStore.isLogin) { next({ name: 'entrance', @@ -23,6 +36,7 @@ router.beforeEach((to, from, next) => { NProgress.done(); return; } + return next(); });