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:
8 files changed
+412
-91
No files matched your search
@@ -1,16 +1,42 @@
|
||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import { Suspense, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Outlet, useNavigate, useRouterState } from '@tanstack/react-router';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useHookProcessOps } from '@/hooks/use-hook-process-ops';
|
||||
import { MainLayout } from '@/components/layout/main-layout';
|
||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { AppStateProvider } from '@/contexts/AppStateContext';
|
||||
import { LayoutProvider } from '@/contexts/LayoutContext';
|
||||
import { LayoutProvider, useLayout } from '@/contexts/LayoutContext';
|
||||
import { useSession } from '@/contexts/SessionContext';
|
||||
import type { AppPath } from '@/router';
|
||||
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
||||
|
||||
/**
|
||||
* Redirects to the operator's configured landing page once (after the layout
|
||||
* config loads), but only when arriving at the root and the target is a real,
|
||||
* non-root nav route — so deep-links and later navigation are respected.
|
||||
* Rendered INSIDE LayoutProvider (needs useLayout).
|
||||
*/
|
||||
function DefaultRouteRedirect() {
|
||||
const { pages, ready } = useLayout();
|
||||
const navigate = useNavigate();
|
||||
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
||||
const done = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ready || done.current) return;
|
||||
done.current = true;
|
||||
const target = pages.defaultRoute;
|
||||
if (target && target !== '/' && pathname === '/' && NAV_ITEMS.some((n) => n.to === target)) {
|
||||
void navigate({ to: target as AppPath });
|
||||
}
|
||||
}, [ready, pages.defaultRoute, pathname, navigate]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The layout route. Owns the live state shared across the four pages
|
||||
* (polling lists, processOps, selectedUin) and renders `<Outlet />` inside
|
||||
@@ -131,6 +157,7 @@ export function AppLayout() {
|
||||
}}
|
||||
>
|
||||
<LayoutProvider>
|
||||
<DefaultRouteRedirect />
|
||||
<MainLayout status={session.status} onLogout={handleLogout}>
|
||||
{/* Routes use `lazyRouteComponent` (router/index.tsx) for
|
||||
code-splitting, which suspends until the chunk is fetched.
|
||||
|
||||
Reference in new issue
Block a user