From 489c79758d713f425b7406f2bcb0343c02139120 Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Thu, 14 May 2026 09:38:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=AA=E6=9C=89admin=E6=89=8D?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=9C=8B=E5=88=B0=E5=B9=B6=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/router/index.ts | 12 ++++++++++++ frontend/src/views/WorkspaceView.vue | 1 + 2 files changed, 13 insertions(+) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 6bdcc3bb..8aa49a6c 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -7,6 +7,7 @@ import AdminView from '../views/AdminView.vue'; import ProfileView from '../views/ProfileView.vue'; import ResetPasswordView from '../views/ResetPasswordView.vue'; import { config } from '../config'; +import { getStoredAuthUser } from '../utils/auth'; const routes = [ { @@ -52,6 +53,17 @@ const router = createRouter({ routes }); +router.beforeEach((to, _from, next) => { + if (to.path === '/admin') { + const user = getStoredAuthUser(); + if (!user || user.role !== 'admin') { + next('/workspace'); + return; + } + } + next(); +}); + router.afterEach((to) => { const baseTitle = config.appTitle || 'AI工作台'; if (to.meta.title) { diff --git a/frontend/src/views/WorkspaceView.vue b/frontend/src/views/WorkspaceView.vue index 6deed09d..7d2e8c8d 100644 --- a/frontend/src/views/WorkspaceView.vue +++ b/frontend/src/views/WorkspaceView.vue @@ -1407,6 +1407,7 @@ onMounted(async () => { 返回聊天