From 603e81853d9b92cdeb7b2e67ed03167b770526a3 Mon Sep 17 00:00:00 2001 From: YoYo Date: Wed, 8 Apr 2026 19:38:06 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E5=9C=A8=E5=8F=97=E4=BF=9D=E6=8A=A4=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E5=88=B0=E9=85=8D=E6=96=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 router/index.js 中为需要登录才能访问的路由(manage、inventory、 projects、mydiary、audit、bugs、users)添加 meta.requiresAuth 标记。 在 UserMenu.vue 的 handleLogout() 中检查当前路由是否需要登录, 如果是则 router.push('/') 跳回配方查询页,否则原地 reload。 Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/components/UserMenu.vue | 6 +++++- frontend/src/router/index.js | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index 16207e1..f9da602 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -136,7 +136,11 @@ function handleLogout() { auth.logout() ui.showToast('已退出登录') emit('close') - window.location.reload() + if (router.currentRoute.value.meta.requiresAuth) { + router.push('/') + } else { + window.location.reload() + } } onMounted(loadNotifications) diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 8fcab38..68a69ff 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -10,11 +10,13 @@ const routes = [ path: '/manage', name: 'RecipeManager', component: () => import('../views/RecipeManager.vue'), + meta: { requiresAuth: true }, }, { path: '/inventory', name: 'Inventory', component: () => import('../views/Inventory.vue'), + meta: { requiresAuth: true }, }, { path: '/oils', @@ -25,26 +27,31 @@ const routes = [ path: '/projects', name: 'Projects', component: () => import('../views/Projects.vue'), + meta: { requiresAuth: true }, }, { path: '/mydiary', name: 'MyDiary', component: () => import('../views/MyDiary.vue'), + meta: { requiresAuth: true }, }, { path: '/audit', name: 'AuditLog', component: () => import('../views/AuditLog.vue'), + meta: { requiresAuth: true }, }, { path: '/bugs', name: 'BugTracker', component: () => import('../views/BugTracker.vue'), + meta: { requiresAuth: true }, }, { path: '/users', name: 'UserManagement', component: () => import('../views/UserManagement.vue'), + meta: { requiresAuth: true }, }, ]