feat(webui): per-page preferences (phase 7)

A `pages` section in config/ui.json (3rd section-merge alongside appearance +
layout):
- defaultRoute: the page to open after login (chosen in Settings → 数据与格式;
  DefaultRouteRedirect navigates there once, only from '/', respecting
  deep-links + later navigation).
- logs: persisted visible levels, max lines, auto-scroll, line-wrap, and
  keyword→colour highlight rules — edited live on the logs page; maxLines is
  read via a ref so it never re-subscribes the SSE.
- processes: pid / name / status sort (persisted, default from prefs).
- config: remembers the last-used tab.

"重置全部" now also clears pages. The server normalizer is total and caps the
logs fields (levels subset, maxLines 100-5000, <=20 highlight rules, trimmed
keywords). Verified by an adversarial review round (normalizePages total
against 30 adversarial inputs; zero MUST/SHOULD-FIX).
This commit is contained in:
DrSmoothl committed 2026-06-13 21:17:24 +08:00
1 parent 7c2923dd04
commit 056fff415c
8 files changed
+412 -91

No files matched your search

@@ -28,7 +28,8 @@ import {
type ThemeMode,
type TimeFormat,
} from '@/contexts/ThemeContext';
import { DEFAULT_LAYOUT } from '@/contexts/LayoutContext';
import { DEFAULT_LAYOUT, DEFAULT_PAGES, useLayout } from '@/contexts/LayoutContext';
import { NAV_ITEMS } from '@/components/layout/sidebar';
import { ChangePasswordDialog } from '@/components/change-password-dialog';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { useApi } from '@/lib/api';
@@ -112,7 +113,7 @@ function AdvancedPanel() {
const doReset = async () => {
setBusy(true);
try {
await api.ui.save({ appearance: DEFAULT_APPEARANCE, layout: DEFAULT_LAYOUT });
await api.ui.save({ appearance: DEFAULT_APPEARANCE, layout: DEFAULT_LAYOUT, pages: DEFAULT_PAGES });
window.location.reload();
} catch {
setBusy(false);
@@ -644,6 +645,7 @@ const TIME_FORMAT_OPTIONS: Opt<TimeFormat>[] = [
function DataPanel() {
const { appearance, setAppearance } = useTheme();
const { pages, setPages } = useLayout();
return (
<div className="flex flex-col gap-5">
<Card>
@@ -662,6 +664,22 @@ function DataPanel() {
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>登录后落地页</CardTitle>
<CardDescription>登录后默认打开的页面。</CardDescription>
</CardHeader>
<CardContent>
<Field label="默认页面">
<Segmented
value={pages.defaultRoute}
options={NAV_ITEMS.map((n) => ({ value: n.to as string, label: n.label }))}
onChange={(defaultRoute) => setPages({ defaultRoute })}
/>
</Field>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2"><Clock className="size-4 text-primary" /> 时间格式</CardTitle>