From b647680576c7d164768f6fbf1d8056294d644d1c Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Fri, 3 Apr 2026 15:13:24 +0800 Subject: [PATCH] update home --- frontend/src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 6f056ed..91ebfd0 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -8,6 +8,7 @@ import { routes } from 'vue-router/auto-routes' import App from './App.vue' import { setTokenGetter } from './utils/request' +import { isAdminOnlyPath } from '@/constants/permissions' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -26,7 +27,6 @@ setTokenGetter(() => useUserStore().token) // 路由守卫 const authWhitelist = ['/login', '/register'] -const adminOnlyPaths = ['/users', '/mq-status', '/roles', '/route-groups'] router.beforeEach(async (to) => { const { useUserStore } = await import('./stores/user') @@ -55,8 +55,8 @@ router.beforeEach(async (to) => { } } - // 角色权限检查:非 admin 不能访问受限路由 - if (adminOnlyPaths.includes(to.path) && !userStore.isAdmin) { + // 角色权限检查:非 admin 不能访问受限路由(前缀匹配) + if (isAdminOnlyPath(to.path) && !userStore.isAdmin) { message.error('无权访问') return '/' }