perf(console): preserve one instance across admin navigation

Use a fixed page key instead of remounting the whole console for each URL. Refresh each view when shown and isolate overview metrics and logs so page filters cannot leak into the dashboard.
This commit is contained in:
翅膀 committed 2026-10-17 14:02:39 +08:00
1 parent 462f1db833
commit de84155e09
3 files changed
+31 -11

No files matched your search

+27 -10
View File
@@ -91,11 +91,11 @@
v-if="view === 'overview'"
:key="refreshKey"
:groups="groups"
:logs="logs"
:metrics="metrics"
:logs="overviewLogs"
:metrics="overviewMetrics"
:groups-loading="groupsLoading"
:logs-loading="logsLoading"
:metrics-loading="metricsLoading"
:logs-loading="overviewLogsLoading"
:metrics-loading="overviewMetricsLoading"
/>
<template v-else-if="selectedGroup">
@@ -525,11 +525,22 @@ const loadingAny = computed(
groupsLoading.value ||
logsLoading.value ||
metricsLoading.value ||
overviewLogsLoading.value ||
overviewMetricsLoading.value ||
groupRoutesLoading.value ||
auditLoading.value,
);
const { logs, loading: logsLoading, error: logsError, load: loadLogs } = useSendLogs();
// Overview shows every group's latest sends and totals, apart from the Send
// Logs and Stats pages and their group filters (the console stays mounted, so
// shared state would carry one page's filter into the other).
const { logs: overviewLogs, loading: overviewLogsLoading, load: loadOverviewLogs } = useSendLogs();
const {
metrics: overviewMetrics,
loading: overviewMetricsLoading,
load: loadOverviewMetrics,
} = useMetrics();
const {
entries: auditEntries,
loading: auditLoading,
@@ -692,17 +703,23 @@ onMounted(() => {
if (params.get("install") === "ok") push(t("install.ok"));
}
loadGroups();
loadLogs(50, logFilterGroup.value || undefined);
loadMetrics();
});
// Tab switches are client-side navigations (no remount), so load the audit
// log whenever the audit view becomes active — including direct deep links.
// The console stays mounted across its pages (the admin page has a fixed
// key), so a page refreshes what it shows whenever it becomes active —
// direct deep links included.
watch(
view,
(v) => {
(v, previous) => {
if (v === "overview") {
loadOverviewLogs(50);
loadOverviewMetrics();
}
if (v === "logs") loadLogs(50, logFilterGroup.value || undefined);
if (v === "audit") loadAudit(50, auditFilterGroup.value || undefined);
if (v === "metrics") loadMetrics(metricsFilterGroup.value || undefined);
// The first load runs on mount; later visits pick up changes made since.
if (previous && (v === "overview" || v === "groups")) loadGroups();
},
{ immediate: true },
);
@@ -816,7 +833,7 @@ watch(
async function refreshOverview(): Promise<void> {
refreshKey.value++;
await Promise.all([loadGroups(), loadLogs(50, logFilterGroup.value || undefined), loadMetrics()]);
await Promise.all([loadGroups(), loadOverviewLogs(50), loadOverviewMetrics()]);
push(t("overview.refreshed"));
}
+3
View File
@@ -2,6 +2,9 @@
import { parseAdminPath } from "~/utils/admin-path";
definePageMeta({
// One console for every /admin path: switching pages keeps its state (and
// its in-flight saves) instead of mounting a fresh copy per URL.
key: "admin-console",
// Unknown console paths (e.g. /admin/foo, /admin/groups/a/b) 404 before rendering.
validate: (route) => parseAdminPath(route.params.slug) !== null,
});