From 72e0d6bccae5007bf4156757d3ebf7a87219bf2c Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 16 Jun 2026 14:28:56 +0800 Subject: [PATCH] feat(webui): static note / link / account widgets (B2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three opt-in static widgets join the GRID_WIDGETS catalogue (hidden by default — enabled from the layout editor), with content stored in block.config: - 便签 (note): pre-wrap plain text, capped at 4000 chars (under the server's 4096-byte config cap). No Markdown. - 链接卡 (link): label + http(s)-only url (javascript:/data: rejected) + an icon from a curated lucide set; renders as a clickable card. - 账号快捷卡 (account): a specified uin's avatar/nickname/online dot, with a datalist of connected accounts in the config form. GridWidgetSpec gains `defaultVisible`, honored by defaultOverviewGrid/Mobile and migrateOverviewBlocks; reconcileLayoutItems gains a `hiddenByDefault` set so the mobile catalogue appends these hidden too. parse* validators keep config total over corrupt input. --- .../src/components/pages/overview-page.tsx | 102 ++++++++++++++-- .../components/pages/widget-config-forms.tsx | 109 +++++++++++++++++- packages/webui/src/contexts/LayoutContext.tsx | 6 +- packages/webui/src/lib/dashboard-layout.ts | 51 +++++++- 4 files changed, 254 insertions(+), 14 deletions(-) diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx index daea3c8d..c0c66b5c 100644 --- a/packages/webui/src/components/pages/overview-page.tsx +++ b/packages/webui/src/components/pages/overview-page.tsx @@ -2,8 +2,8 @@ import { useEffect, useMemo, useState, type ReactNode } from 'react'; import { motion, Reorder } from 'motion/react'; import { Link } from '@tanstack/react-router'; import { - Activity, ArrowRight, Bell, Cable, Check, Cpu, Eye, EyeOff, GripVertical, MemoryStick, - MonitorCog, Pencil, PlugZap, RefreshCw, RotateCcw, Server, Settings2, Users, + Activity, ArrowRight, Bell, Cable, Check, Cpu, ExternalLink, Eye, EyeOff, GripVertical, + MemoryStick, MonitorCog, Pencil, PlugZap, RefreshCw, RotateCcw, Server, Settings2, Users, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; @@ -21,14 +21,17 @@ import { useTheme } from '@/contexts/ThemeContext'; import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; import { useMediaQuery } from '@/hooks/use-media-query'; import { - CONFIGURABLE_WIDGETS, GRID_COLS, MOBILE_WIDGET_IDS, mobileHeightOf, - parseAlertsConfig, parseConnectionsConfig, parseHostConfig, parseSessionsConfig, widgetLabel, - type AlertsConfig, type ConnectionsConfig, type HostConfig, type SessionsConfig, + CONFIGURABLE_WIDGETS, GRID_COLS, MOBILE_WIDGET_IDS, STATIC_WIDGET_IDS, mobileHeightOf, + parseAccountConfig, parseAlertsConfig, parseConnectionsConfig, parseHostConfig, + parseLinkConfig, parseNoteConfig, parseSessionsConfig, widgetLabel, + type AccountConfig, type AlertsConfig, type ConnectionsConfig, type HostConfig, + type LinkConfig, type NoteConfig, type SessionsConfig, } from '@/lib/dashboard-layout'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { DashboardGrid, type GridCoord } from '@/components/pages/dashboard-grid'; import { - AlertsConfigForm, ConnectionsConfigForm, HostConfigForm, SessionsConfigForm, + AccountConfigForm, AlertsConfigForm, ConnectionsConfigForm, HostConfigForm, + LinkConfigForm, LINK_ICON_COMPONENTS, NoteConfigForm, SessionsConfigForm, } from '@/components/pages/widget-config-forms'; function qqAvatarUrl(uin: string) { @@ -42,6 +45,9 @@ function renderWidget(block: UiLayoutItem): ReactNode { case 'alerts': return ; case 'host': return ; case 'sessions': return ; + case 'note': return ; + case 'link': return ; + case 'account': return ; default: return null; } } @@ -71,7 +77,7 @@ export function OverviewPage() { // Reconcile the mobile order against the live widget catalogue (drop unknown, // append new as visible) — so a widget added later just appears on phones too. const mobileItems = useMemo( - () => reconcileLayoutItems(overviewMobile, MOBILE_WIDGET_IDS), + () => reconcileLayoutItems(overviewMobile, MOBILE_WIDGET_IDS, [], STATIC_WIDGET_IDS), [overviewMobile], ); @@ -184,6 +190,9 @@ export function OverviewPage() { {configBlock?.id === 'sessions' && setBlockConfig('sessions', c)} />} {configBlock?.id === 'host' && setBlockConfig('host', c)} />} {configBlock?.id === 'connections' && setBlockConfig('connections', c)} />} + {configBlock?.id === 'note' && setBlockConfig('note', c)} />} + {configBlock?.id === 'link' && setBlockConfig('link', c)} />} + {configBlock?.id === 'account' && setBlockConfig('account', c)} />} @@ -652,6 +661,85 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) { ); } +// ─────────────── static widgets (note / link / account) ─────────────── + +function NoteWidget({ config }: { config: NoteConfig }) { + return ( + + + {config.text.trim() ? ( +

{config.text}

+ ) : ( +

空便签 · 在编辑模式点齿轮填写内容

+ )} +
+
+ ); +} + +function LinkWidget({ config }: { config: LinkConfig }) { + const Icon = LINK_ICON_COMPONENTS[config.icon] ?? LINK_ICON_COMPONENTS.link; + if (!config.url) { + return ( + + + + 未配置链接 · 点齿轮设置 + + + ); + } + return ( + + + +
+ +
+
+

{config.label || config.url}

+

{config.url}

+
+ +
+
+
+ ); +} + +function AccountWidget({ config }: { config: AccountConfig }) { + const { qqList } = useAppState(); + const acct = qqList.find((q) => q.uin === config.uin); + if (!config.uin) { + return ( + + + + 未指定账号 · 点齿轮设置 + + + ); + } + return ( + + + + + {(acct?.nickname || config.uin).slice(0, 2)} + +
+

{acct?.nickname || '未接入账号'}

+

{config.uin}

+
+ +
+
+ ); +} + // ─────────────── recent alerts ─────────────── const ALERT_LEVEL_CLASS: Record = { diff --git a/packages/webui/src/components/pages/widget-config-forms.tsx b/packages/webui/src/components/pages/widget-config-forms.tsx index 719bf4b0..5cacae40 100644 --- a/packages/webui/src/components/pages/widget-config-forms.tsx +++ b/packages/webui/src/components/pages/widget-config-forms.tsx @@ -1,10 +1,21 @@ +import { useId } from 'react'; +import { Bell, BookOpen, ExternalLink, Github, Globe, Link2, Server, Star } from 'lucide-react'; import { Input } from '@/components/ui/input'; import { ToggleSwitch } from '@/components/ui/toggle-switch'; import { cn } from '@/lib/utils'; +import { useAppState } from '@/contexts/AppStateContext'; import { - ALL_LOG_LEVELS, parseAlertsConfig, parseConnectionsConfig, parseHostConfig, parseSessionsConfig, + ALL_LOG_LEVELS, LINK_ICON_IDS, NOTE_MAX, + parseAlertsConfig, parseAccountConfig, parseConnectionsConfig, parseHostConfig, + parseLinkConfig, parseNoteConfig, parseSessionsConfig, } from '@/lib/dashboard-layout'; +/** Curated link-card icons, shared by the picker form and the widget renderer. */ +export const LINK_ICON_COMPONENTS: Record = { + link: Link2, external: ExternalLink, github: Github, book: BookOpen, + server: Server, globe: Globe, star: Star, bell: Bell, +}; + // Per-widget config forms, shown inside a dialog opened from a dashboard // widget's edit-overlay gear. `config` is the widget's opaque block.config; // `onChange` merges a partial back via setBlockConfig. @@ -155,3 +166,99 @@ export function ConnectionsConfigForm({ config, onChange }: FormProps) { ); } + +export function NoteConfigForm({ config, onChange }: FormProps) { + const c = parseNoteConfig(config); + return ( +
+ 便签内容(纯文本,保留换行) +