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 @@ - +