From 23048894b5f6b178cbf2a0224c8c2f69bae42b58 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 16 Jun 2026 14:20:23 +0800 Subject: [PATCH] feat(webui): top-bar element show/hide (B2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The top-bar's optional right-side elements (connection-status badge, theme toggle) are now toggleable via `topbarItems`. Essential controls — the menu/collapse button, page title, and logout — always render and aren't listed. - A TOPBAR_CATALOGUE (id+label) drives both the render gating and the settings toggles; TopBar reconciles `topbarItems` against it so a new element defaults to shown. - A 顶栏 group in settings → 外观 exposes one switch per catalogue element. --- .../webui/src/components/layout/top-bar.tsx | 39 ++++++++++++++----- .../src/components/pages/settings-page.tsx | 26 ++++++++++++- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/packages/webui/src/components/layout/top-bar.tsx b/packages/webui/src/components/layout/top-bar.tsx index e86993ee..6b2cf7ff 100644 --- a/packages/webui/src/components/layout/top-bar.tsx +++ b/packages/webui/src/components/layout/top-bar.tsx @@ -7,6 +7,14 @@ import { Badge } from '@/components/ui/badge'; import { ThemeToggle } from '@/components/theme-toggle'; import { ConfirmDialog } from '@/components/confirm-dialog'; import { NAV_ITEMS } from '@/components/layout/sidebar'; +import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; + +// Toggleable top-bar elements (the menu/title/logout are essential and always +// render). Labels drive the settings toggles; ids match `topbarItems`. +export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [ + { id: 'status', label: '连接状态徽章' }, + { id: 'theme', label: '主题切换按钮' }, +]; interface TopBarProps { status: string; @@ -34,6 +42,15 @@ export function TopBar({ const PageIcon = meta?.icon; const online = status === '已连接'; + // Which optional top-bar elements the operator has kept (reconciled against + // the live catalogue, so a new element defaults to shown). + const { topbarItems } = useLayout(); + const shown = new Set( + reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id)) + .filter((i) => i.visible) + .map((i) => i.id), + ); + return (
{/* Collapse toggle (desktop) / menu (mobile) */} @@ -73,17 +90,19 @@ export function TopBar({
- - - {status} - + {shown.has('status') && ( + + + {status} + + )} - + {shown.has('theme') && }