From e08f0e153c8616d19b9fd53b21af2201e9994484 Mon Sep 17 00:00:00 2001 From: ktianc Date: Mon, 22 Jan 2024 22:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=AD=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E9=87=8D=E6=96=B0=E6=89=93=E5=BC=80=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=BF=9B=E5=85=A5=E5=8A=A8=E6=80=81=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kinit-admin/src/permission.ts | 5 +++++ kinit-admin/src/router/index.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/kinit-admin/src/permission.ts b/kinit-admin/src/permission.ts index 18a747a..b14a408 100644 --- a/kinit-admin/src/permission.ts +++ b/kinit-admin/src/permission.ts @@ -1,3 +1,4 @@ +import { hasRoute } from './router' import router from './router' import type { RouteRecordRaw } from 'vue-router' import { useTitle } from '@/hooks/web/useTitle' @@ -18,6 +19,7 @@ router.beforeEach(async (to, from, next) => { loadStart() const permissionStore = usePermissionStoreWithOut() const authStore = useAuthStoreWithOut() + if (authStore.getToken) { if (to.path === '/login') { next({ path: '/' }) @@ -28,6 +30,9 @@ router.beforeEach(async (to, from, next) => { await authStore.setUserInfo() } if (permissionStore.getIsAddRouters) { + if (!hasRoute(to.path)) { + authStore.logout('认证已过期,请重新登录!') + } next() return } diff --git a/kinit-admin/src/router/index.ts b/kinit-admin/src/router/index.ts index b8572be..b84b124 100644 --- a/kinit-admin/src/router/index.ts +++ b/kinit-admin/src/router/index.ts @@ -124,6 +124,12 @@ export const resetRouter = (): void => { }) } +// 判断是否已经有某个路径的路由配置 +export const hasRoute = (path: string): boolean => { + const resolvedRoute = router.resolve(path) + return resolvedRoute.matched.length > 0 +} + export const setupRouter = (app: App) => { app.use(router) }