From 58951419266a76c60de9cc1994bc96910f3604ec Mon Sep 17 00:00:00 2001 From: Nixevol Date: Wed, 28 Oct 2026 03:42:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8C=E7=99=BB=E5=BD=95=E5=90=8E=E6=8C=89?= =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=BF=9B=E5=85=A5=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=88=96=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/App.vue | 45 ++- web/src/features/admin/SettingsView.vue | 185 ++++++++++++ web/src/features/admin/UsersView.vue | 359 ++++++++++++++++++++++++ web/src/features/auth/LoginView.vue | 49 +++- web/src/shared/session.ts | 22 ++ web/src/shell/AdminShell.vue | 84 ++++++ web/src/shell/adminNavigation.ts | 15 + web/src/styles.css | 153 ++++++++++ 8 files changed, 898 insertions(+), 14 deletions(-) create mode 100644 web/src/features/admin/SettingsView.vue create mode 100644 web/src/features/admin/UsersView.vue create mode 100644 web/src/shared/session.ts create mode 100644 web/src/shell/AdminShell.vue create mode 100644 web/src/shell/adminNavigation.ts diff --git a/web/src/App.vue b/web/src/App.vue index 3375121..a05bd1f 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -3,31 +3,61 @@ import { onMounted, ref } from "vue"; import { darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui"; import LoginView from "./features/auth/LoginView.vue"; import Shell from "./shell/Shell.vue"; +import AdminShell from "./shell/AdminShell.vue"; import { isDark, themeOverrides } from "./shared/theme"; +import { sessionFromPayload, type AppSession } from "./shared/session"; const ready = ref(false); -const employeeId = ref(""); +const session = ref(null); + +function applyPayload(payload: unknown) { + if (!payload || typeof payload !== "object") return null; + return sessionFromPayload(payload); +} onMounted(async () => { try { const response = await fetch("/api/session"); if (response.ok) { - const payload = await response.json(); - employeeId.value = String(payload.employee_id || ""); + session.value = applyPayload(await response.json().catch(() => null)); } } finally { ready.value = true; } }); +async function reloadSession() { + try { + const response = await fetch("/api/session"); + if (response.status === 401) { + session.value = null; + return; + } + if (!response.ok) return; + const next = applyPayload(await response.json().catch(() => null)); + if (next) session.value = next; + } catch { + return; + } +} + async function exitSystem() { await fetch("/api/logout", { method: "POST" }); - employeeId.value = ""; + session.value = null; } async function revokeAccount() { await fetch("/api/revoke", { method: "POST" }); - employeeId.value = ""; + session.value = null; +} + +async function exitAdmin() { + await fetch("/api/admin/logout", { method: "POST" }); + session.value = null; +} + +function onLogin(next: AppSession) { + session.value = next; } @@ -36,8 +66,9 @@ async function revokeAccount() {
- - + + +
diff --git a/web/src/features/admin/SettingsView.vue b/web/src/features/admin/SettingsView.vue new file mode 100644 index 0000000..81233c3 --- /dev/null +++ b/web/src/features/admin/SettingsView.vue @@ -0,0 +1,185 @@ + + + diff --git a/web/src/features/admin/UsersView.vue b/web/src/features/admin/UsersView.vue new file mode 100644 index 0000000..9d6df9c --- /dev/null +++ b/web/src/features/admin/UsersView.vue @@ -0,0 +1,359 @@ + + + diff --git a/web/src/features/auth/LoginView.vue b/web/src/features/auth/LoginView.vue index f665ab0..fc81b5e 100644 --- a/web/src/features/auth/LoginView.vue +++ b/web/src/features/auth/LoginView.vue @@ -1,8 +1,9 @@ + + diff --git a/web/src/shell/adminNavigation.ts b/web/src/shell/adminNavigation.ts new file mode 100644 index 0000000..22e1afd --- /dev/null +++ b/web/src/shell/adminNavigation.ts @@ -0,0 +1,15 @@ +import type { Component } from "vue"; +import { h } from "vue"; +import { NIcon } from "naive-ui"; +import { PeopleOutline, SettingsOutline } from "@vicons/ionicons5"; + +function renderIcon(icon: Component) { + return () => h(NIcon, null, { default: () => h(icon) }); +} + +export type AdminPageKey = "users" | "settings"; + +export const adminNavOptions = [ + { label: "用户管理", key: "users" as const, icon: renderIcon(PeopleOutline) }, + { label: "系统配置", key: "settings" as const, icon: renderIcon(SettingsOutline) }, +]; diff --git a/web/src/styles.css b/web/src/styles.css index c2dc508..3855ed1 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -696,3 +696,156 @@ select { grid-template-columns: minmax(0, 1fr); } } + +.admin-page { + overflow: hidden; +} + +.admin-page .page-head { + flex: none; + align-items: center; +} + +.admin-page .page-head h2 { + margin: 0; +} + +.admin-page > .settings-form { + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; +} + +.admin-alert { + flex: none; + margin-bottom: 12px; +} + +.admin-scroll { + flex: 1; + min-height: 0; + overflow: auto; + overscroll-behavior: contain; +} + +.admin-status { + margin: 0; + color: var(--muted); +} + +.settings-form .form-row { + grid-template-columns: max-content minmax(160px, 280px); + justify-content: start; +} + +.settings-form .form-row label { + min-width: 15em; + white-space: nowrap; +} + +.setting-control { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; +} + +.setting-control .n-input-number { + flex: 1; + width: 100%; + min-width: 0; +} + +.setting-unit { + flex: none; + color: var(--muted); +} + +.admin-table { + width: 100%; + min-width: 820px; + border-collapse: collapse; +} + +.admin-table th, +.admin-table td { + padding: 10px 16px 10px 0; + border-bottom: 1px solid var(--line); + text-align: left; + vertical-align: middle; +} + +.admin-table th { + position: sticky; + top: 0; + z-index: 1; + background: var(--bg); + color: var(--muted); + font-size: 12px; + font-weight: 400; +} + +.admin-table .employee, +.admin-table .when { + font-variant-numeric: tabular-nums; + white-space: nowrap; +} + +.admin-table .ok { + color: var(--accent); +} + +.admin-table .late { + color: var(--danger); +} + +.admin-table .quiet { + color: var(--muted); +} + +.row-actions { + display: flex; + flex-wrap: wrap; + gap: 8px; +} + +.credential-note { + margin: 0 0 12px; +} + +.secret-field { + padding: 8px 0; + border-bottom: 1px solid var(--line); +} + +.secret-field:last-child { + border-bottom: 0; +} + +.secret-label { + margin-bottom: 4px; + color: var(--muted); + font-size: 12px; +} + +.secret-value { + overflow-wrap: anywhere; + word-break: break-all; +} + +.modal-actions { + display: flex; + justify-content: flex-end; +} + +@media (max-width: 800px) { + .settings-form .form-row { + grid-template-columns: minmax(0, 1fr); + } + + .settings-form .form-row label { + min-width: 0; + white-space: normal; + } +}