From b4357f7876631f217da32c3a7d5701114e591147 Mon Sep 17 00:00:00 2001 From: shirainbown Date: Fri, 19 Jun 2026 13:05:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=AF=E7=94=B1=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=20-=20=E8=AE=BF=E5=AE=A2=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=9C=BA=E5=99=A8=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?admin=E9=A1=B5=E9=9D=A2=E9=9C=80=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/MainLayout.vue | 68 ++++--------------------------- web/src/router/index.js | 23 ++++------- web/src/views/MachineList.vue | 2 +- 3 files changed, 19 insertions(+), 74 deletions(-) diff --git a/web/src/components/MainLayout.vue b/web/src/components/MainLayout.vue index 257e41c..be4b003 100644 --- a/web/src/components/MainLayout.vue +++ b/web/src/components/MainLayout.vue @@ -39,8 +39,8 @@
- {{ isAdmin ? '管理员' : '访客' }} - {{ isAdmin ? 'Admin' : 'Guest' }} + 管理员 + Admin
- -
-
- LAN Manager - LAN Manager -
-
- -
-
- -
+ +
@@ -386,54 +376,14 @@ html.dark .brand-logo { background: var(--page-bg); transition: background .25s ease; } +.main.no-sidebar { + margin-left: 0; +} + .main-inner { padding: 10px; } -.guest-main { - margin-left: 0; - padding-top: 48px; -} - -.guest-header { - position: fixed; - top: 0; - left: 0; - right: 0; - height: 48px; - background: var(--sidebar-bg); - border-bottom: 1px solid var(--border); - display: flex; - align-items: center; - justify-content: space-between; - padding: 0 16px; - z-index: 100; -} -.guest-brand { - display: flex; - align-items: center; - gap: 8px; - font-weight: 600; - font-size: 14px; - color: var(--text-primary); -} -.guest-theme-toggle { - width: 32px; - height: 32px; - border-radius: 50%; - background: var(--card-bg); - border: 1px solid var(--border); - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; - color: var(--text); - transition: all .2s ease; -} -.guest-theme-toggle:hover { - background: var(--hover-bg); -} - @media (max-width: 768px) { .sidebar { width: 64px; } .brand-text, .nav-item span, .user-meta, .footer-btn span, .theme-toggle span { display: none; } @@ -442,6 +392,6 @@ html.dark .brand-logo { .user-info { justify-content: center; padding: 10px; } .theme-toggle { justify-content: center; padding: 10px; } .main { margin-left: 64px; } - .guest-main { margin-left: 0; } + .main.no-sidebar { margin-left: 0; } } diff --git a/web/src/router/index.js b/web/src/router/index.js index 49f2955..5db560b 100644 --- a/web/src/router/index.js +++ b/web/src/router/index.js @@ -6,7 +6,7 @@ const routes = [ path: '/login', name: 'Login', component: () => import('@/views/Login.vue'), - meta: { public: true, guestOnly: true }, + meta: { guestOnly: true }, }, { path: '/', @@ -59,30 +59,25 @@ router.beforeEach(async (to, from, next) => { if (!authChecked) { try { const { data } = await checkAuth() - authState = { ...data, is_logged_in: true } + authState = { is_admin: data.is_admin, is_logged_in: true } } catch (e) { authState = { is_admin: false, is_logged_in: false } } authChecked = true } - // 未登录,且不是公开页面也不是登录页 → 强制去登录 - if (!authState.is_logged_in && !to.meta.public && !to.meta.guestOnly) { - return next('/login?redirect=' + encodeURIComponent(to.fullPath)) + // 未登录用户访问 admin 专属页面 → 去机器列表 + if (!authState.is_logged_in && to.meta.admin) { + return next('/machines') } - // 已登录访客,访问需要 admin 的页面 → 去机器列表 + // 已登录但非管理员(防御性)访问 admin 页面 → 去机器列表 if (authState.is_logged_in && !authState.is_admin && to.meta.admin) { return next('/machines') } - // 已登录访客,访问登录页 → 去机器列表 - if (authState.is_logged_in && !authState.is_admin && to.meta.guestOnly) { - return next('/machines') - } - - // 管理员访问登录页 → 去仪表盘 - if (authState.is_admin && to.meta.guestOnly) { + // 管理员已登录,访问登录页 → 去仪表盘 + if (authState.is_logged_in && authState.is_admin && to.meta.guestOnly) { return next('/dashboard') } @@ -95,7 +90,7 @@ export function refreshAuth() { } export function setAuth(data) { - authState = { ...data, is_logged_in: true } + authState = { is_admin: data.is_admin, is_logged_in: true } } export function getAuth() { diff --git a/web/src/views/MachineList.vue b/web/src/views/MachineList.vue index a143940..3561142 100644 --- a/web/src/views/MachineList.vue +++ b/web/src/views/MachineList.vue @@ -115,7 +115,7 @@ - +