From 9be3b9050931a7c13318b8bb83cccdb6e5d6a160 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Tue, 3 Nov 2026 09:37:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=90=E8=A1=8C=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E7=A9=BA=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=86=8D=E6=8A=8A=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=92=91=E5=B4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/features/admin/ChartPane.vue | 2 +- web/src/features/admin/DashboardView.vue | 72 +++++++++++++++--------- web/src/main.ts | 4 ++ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/web/src/features/admin/ChartPane.vue b/web/src/features/admin/ChartPane.vue index 4cf6be5..df1ce96 100644 --- a/web/src/features/admin/ChartPane.vue +++ b/web/src/features/admin/ChartPane.vue @@ -23,7 +23,7 @@ function resize() { } onMounted(() => { - render(); + requestAnimationFrame(render); window.addEventListener("resize", resize); }); diff --git a/web/src/features/admin/DashboardView.vue b/web/src/features/admin/DashboardView.vue index bb1fb07..9b49af4 100644 --- a/web/src/features/admin/DashboardView.vue +++ b/web/src/features/admin/DashboardView.vue @@ -21,29 +21,48 @@ interface PoolDash { cities: { name: string; count: number }[]; } +function emptyPool(): PoolDash { + return { + total: 0, + valid: 0, + invalid: 0, + sessionOpen: 0, + sessionClosed: 0, + addedToday: 0, + addedWeek: 0, + userRole: 0, + adminRole: 0, + dailyAdded: [], + cities: [], + }; +} + +function readPool(result: unknown): PoolDash | null { + if (!result || typeof result !== "object") return null; + const body = result as Partial & { pool?: Partial }; + const source = body.pool && typeof body.pool === "object" ? body.pool : body; + if (typeof source.total !== "number") return null; + const blank = emptyPool(); + return { + ...blank, + ...source, + dailyAdded: Array.isArray(source.dailyAdded) ? source.dailyAdded : blank.dailyAdded, + cities: Array.isArray(source.cities) ? source.cities : blank.cities, + }; +} + const toast = useToast(); const loaded = ref(false); -const pool = ref({ - total: 0, - valid: 0, - invalid: 0, - sessionOpen: 0, - sessionClosed: 0, - addedToday: 0, - addedWeek: 0, - userRole: 0, - adminRole: 0, - dailyAdded: [], - cities: [], -}); +const accountPool = ref(emptyPool()); +const stats = computed(() => accountPool.value ?? emptyPool()); const cards = computed(() => [ - { label: "账号总数", value: pool.value.total }, - { label: "今日新增", value: pool.value.addedToday }, - { label: "近7日新增", value: pool.value.addedWeek }, - { label: "有效凭证", value: pool.value.valid, tone: "ok" }, - { label: "失效凭证", value: pool.value.invalid, tone: pool.value.invalid ? "bad" : "" }, - { label: "未退出", value: pool.value.sessionOpen, tone: "run" }, + { label: "账号总数", value: stats.value.total }, + { label: "今日新增", value: stats.value.addedToday }, + { label: "近7日新增", value: stats.value.addedWeek }, + { label: "有效凭证", value: stats.value.valid, tone: "ok" }, + { label: "失效凭证", value: stats.value.invalid, tone: stats.value.invalid ? "bad" : "" }, + { label: "未退出", value: stats.value.sessionOpen, tone: "run" }, ]); function theme() { @@ -71,7 +90,7 @@ function axis(colors: ReturnType) { const dailyOption = computed(() => { const colors = theme(); void isDark.value; - const days = pool.value.dailyAdded; + const days = stats.value.dailyAdded; return { color: [colors.accent], tooltip: { trigger: "axis" }, @@ -96,8 +115,8 @@ const statusOption = computed(() => { const colors = theme(); void isDark.value; const items = [ - { name: "有效", value: pool.value.valid, itemStyle: { color: colors.ok } }, - { name: "失效", value: pool.value.invalid, itemStyle: { color: colors.danger } }, + { name: "有效", value: stats.value.valid, itemStyle: { color: colors.ok } }, + { name: "失效", value: stats.value.invalid, itemStyle: { color: colors.danger } }, ]; return { tooltip: { trigger: "item" }, @@ -107,7 +126,7 @@ const statusOption = computed(() => { radius: ["42%", "68%"], center: ["50%", "44%"], label: { color: colors.ink, formatter: "{b} {c}" }, - data: pool.value.total ? items : [{ name: "暂无", value: 1, itemStyle: { color: colors.line }, label: { show: false } }], + data: stats.value.total ? items : [{ name: "暂无", value: 1, itemStyle: { color: colors.line }, label: { show: false } }], }], }; }); @@ -115,7 +134,7 @@ const statusOption = computed(() => { const cityOption = computed(() => { const colors = theme(); void isDark.value; - const rows = pool.value.cities.slice(0, 8); + const rows = stats.value.cities.slice(0, 8); return { color: [colors.accent], tooltip: { trigger: "axis" }, @@ -139,8 +158,9 @@ const cityOption = computed(() => { async function load() { try { - const result = await api<{ pool: PoolDash }>("/api/admin/dashboard"); - pool.value = result.pool; + const next = readPool(await api("/api/admin/dashboard")); + if (!next) throw new Error("运行面板没有获取到"); + accountPool.value = next; loaded.value = true; } catch (error) { toast.error(error instanceof Error ? error.message : "运行面板没有获取到"); diff --git a/web/src/main.ts b/web/src/main.ts index fcb44e0..8309231 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -1,4 +1,8 @@ import { createApp } from "vue"; + +window.addEventListener("error", (event) => { + if (event.message?.includes("ResizeObserver loop")) event.stopImmediatePropagation(); +}); import { createRouter, createWebHistory } from "vue-router"; import App from "./App.vue"; import InstallView from "./features/install/InstallView.vue";