From a61e0a253deff2d464c32ac504b72d7ea23b5b15 Mon Sep 17 00:00:00 2001
From: DrSmoothl <1787882683@qq.com>
Date: Sat, 13 Jun 2026 21:45:41 +0800
Subject: [PATCH] feat(webui): in-place dashboard edit overlays + inline
sidebar reorder
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Rework the layout edit mode from a separate panel to in-place affordances:
- Each dashboard widget gets a semi-transparent floating overlay in edit mode:
a "拖动" grip bar (the whole card is the drag target — forgiving +
discoverable), an eye to show/hide, and a gear that opens the per-widget
settings in a dialog. Hidden widgets show as re-enableable "已隐藏" ghosts;
the bottom-right resize grip is now clearly visible.
- The sidebar nav becomes a drag-to-reorder list directly in the sidebar
(show/hide + locked pinned items + a 完成 button); editing force-expands the
sidebar (and disables the collapse toggle). Edit mode is a shared
LayoutContext flag so one "编辑布局" toggle drives both the grid and the nav.
- The separate editor panel (overview-layout-editor) is removed; the gear
opens config in a dialog instead.
Also: stat-tile typography tightened (leading-tight, smaller value, overflow
clip) so text no longer hugs the edge on small/short tiles. Verified by an
adversarial review round (no MUST-FIX).
---
.../src/components/layout/main-layout.tsx | 12 +-
.../webui/src/components/layout/sidebar.tsx | 142 +++++++---
.../webui/src/components/layout/top-bar.tsx | 6 +-
.../src/components/pages/dashboard-grid.tsx | 79 +++++-
.../pages/overview-layout-editor.tsx | 244 ------------------
.../src/components/pages/overview-page.tsx | 88 ++++---
.../components/pages/widget-config-forms.tsx | 85 ++++++
packages/webui/src/contexts/LayoutContext.tsx | 9 +-
packages/webui/src/index.css | 23 +-
9 files changed, 339 insertions(+), 349 deletions(-)
delete mode 100644 packages/webui/src/components/pages/overview-layout-editor.tsx
create mode 100644 packages/webui/src/components/pages/widget-config-forms.tsx
diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx
index 0006f9dc..2c8b96df 100644
--- a/packages/webui/src/components/layout/main-layout.tsx
+++ b/packages/webui/src/components/layout/main-layout.tsx
@@ -7,6 +7,7 @@ import { Sidebar } from '@/components/layout/sidebar';
import { TopBar } from '@/components/layout/top-bar';
import { useMediaQuery } from '@/hooks/use-media-query';
import { useTheme } from '@/contexts/ThemeContext';
+import { useLayout } from '@/contexts/LayoutContext';
import { cn } from '@/lib/utils';
interface MainLayoutProps {
@@ -27,6 +28,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
return appearance.sidebarDefaultCollapsed;
});
const customBg = appearance.background.type !== 'none';
+ const { editing } = useLayout();
+ // Force the sidebar open while editing layout so its drag-to-reorder list
+ // has room (it returns to the user's collapsed pref on 完成).
+ const effectiveCollapsed = collapsed && !editing;
const [mobileOpen, setMobileOpen] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -40,11 +45,11 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
{!isMobile && (
-
+
)}
@@ -66,11 +71,12 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
setCollapsed((v) => !v)}
onOpenMobile={() => setMobileOpen(true)}
onLogout={onLogout}
isMobile={isMobile}
+ editing={editing}
/>
diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx
index 37024a0b..e92f30dd 100644
--- a/packages/webui/src/components/layout/sidebar.tsx
+++ b/packages/webui/src/components/layout/sidebar.tsx
@@ -1,5 +1,5 @@
-import { LayoutDashboard, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
-import { motion } from 'motion/react';
+import { Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
+import { motion, Reorder } from 'motion/react';
import { Link, useRouterState } from '@tanstack/react-router';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Separator } from '@/components/ui/separator';
@@ -38,15 +38,23 @@ interface SidebarProps {
export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
const pathname = useRouterState({ select: (s) => s.location.pathname });
const { updateInfo } = useAppState();
- const { navItems } = useLayout();
+ const { navItems, setNavItems, editing, setEditing } = useLayout();
- // Render nav in the operator's configured order, hidden items removed,
- // pinned items forced on, and forward-compatible with future routes.
- const orderedNav = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV)
+ // Full reconciled nav (incl. hidden) — pinned forced visible, forward-compat.
+ const reconciled = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV);
+ // View mode: configured order, hidden removed.
+ const orderedNav = reconciled
.filter((i) => i.visible)
.map((i) => NAV_ITEMS.find((n) => n.to === i.id))
.filter((n): n is NavItem => !!n);
+ const reorderNav = (ids: string[]) => {
+ const byId = new Map(reconciled.map((i) => [i.id, i]));
+ setNavItems(ids.map((id) => byId.get(id)).filter((x): x is NonNullable => !!x));
+ };
+ const toggleNav = (id: string) =>
+ setNavItems(reconciled.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i)));
+
return (
{/* Brand */}
@@ -67,42 +75,94 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
{/* Nav */}
-
- {orderedNav.map(({ to, label, icon: Icon, description }) => {
- const isActive = pathname === to;
- return (
-
+
+ 编辑导航
+ setEditing(false)}
+ className="inline-flex items-center gap-1 rounded-md border border-primary/40 bg-primary/10 px-2 py-0.5 text-[11px] text-primary transition-colors hover:bg-primary/15 cursor-pointer"
>
- {isActive && (
-
- )}
-
- {!collapsed && (
-
- {label}
- {description}
-
- )}
-
- );
- })}
-
+ 完成
+
+
+ i.id)} onReorder={reorderNav} className="flex flex-col gap-1">
+ {reconciled.map((item) => {
+ const meta = NAV_ITEMS.find((n) => n.to === item.id);
+ if (!meta) return null;
+ const Icon = meta.icon;
+ const pinned = (PINNED_NAV as string[]).includes(item.id);
+ return (
+
+
+
+ {meta.label}
+ {pinned ? (
+
+
+
+ ) : (
+ toggleNav(item.id)}
+ title={item.visible ? '隐藏' : '显示'}
+ aria-label={item.visible ? '隐藏' : '显示'}
+ className="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-sidebar-accent/50 hover:text-foreground cursor-pointer"
+ >
+ {item.visible ? : }
+
+ )}
+
+ );
+ })}
+
+
+ ) : (
+
+ {orderedNav.map(({ to, label, icon: Icon, description }) => {
+ const isActive = pathname === to;
+ return (
+
+ {isActive && (
+
+ )}
+
+ {!collapsed && (
+
+ {label}
+ {description}
+
+ )}
+
+ );
+ })}
+
+ )}
diff --git a/packages/webui/src/components/layout/top-bar.tsx b/packages/webui/src/components/layout/top-bar.tsx
index b5198cbe..e86993ee 100644
--- a/packages/webui/src/components/layout/top-bar.tsx
+++ b/packages/webui/src/components/layout/top-bar.tsx
@@ -15,6 +15,8 @@ interface TopBarProps {
onOpenMobile: () => void;
onLogout: () => void;
isMobile: boolean;
+ /** Layout edit mode force-expands the sidebar, so collapsing is disabled. */
+ editing?: boolean;
}
export function TopBar({
@@ -24,6 +26,7 @@ export function TopBar({
onOpenMobile,
onLogout,
isMobile,
+ editing = false,
}: TopBarProps) {
const [confirmLogout, setConfirmLogout] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -43,8 +46,9 @@ export function TopBar({
variant="ghost"
size="icon-sm"
onClick={onToggleCollapse}
+ disabled={editing}
aria-label={collapsed ? '展开侧边栏' : '收起侧边栏'}
- title={collapsed ? '展开侧边栏' : '收起侧边栏'}
+ title={editing ? '编辑布局时侧栏保持展开' : collapsed ? '展开侧边栏' : '收起侧边栏'}
>
{collapsed ? : }
diff --git a/packages/webui/src/components/pages/dashboard-grid.tsx b/packages/webui/src/components/pages/dashboard-grid.tsx
index b6282d44..9a94261a 100644
--- a/packages/webui/src/components/pages/dashboard-grid.tsx
+++ b/packages/webui/src/components/pages/dashboard-grid.tsx
@@ -1,6 +1,7 @@
import { useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
import { GridStack, type GridStackWidget } from 'gridstack';
+import { Eye, EyeOff, GripVertical, Settings2 } from 'lucide-react';
import 'gridstack/dist/gridstack.css';
import { GRID_CELL_HEIGHT, GRID_MARGIN, minSizeOf } from '@/lib/dashboard-layout';
import { cn } from '@/lib/utils';
@@ -9,7 +10,8 @@ import type { UiLayoutItem } from '@/types';
export interface GridCoord { id: string; x: number; y: number; w: number; h: number }
interface DashboardGridProps {
- /** Visible blocks, each with x/y/w/h (already migrated/positioned). */
+ /** Blocks to render — visible-only in view mode, ALL (incl. hidden) in edit
+ * mode so hidden widgets show as re-enableable ghosts. Each has x/y/w/h. */
blocks: UiLayoutItem[];
editing: boolean;
/** Column count — 12 on desktop, 1 on narrow screens (auto single-column). */
@@ -17,6 +19,11 @@ interface DashboardGridProps {
/** Fired (debounced upstream) after a drag/resize settles. */
onChange: (coords: GridCoord[]) => void;
renderWidget: (block: UiLayoutItem) => ReactNode;
+ // ── edit overlay ──
+ labelFor: (id: string) => string;
+ configurableIds: ReadonlySet;
+ onToggleVisible: (id: string) => void;
+ onConfigOpen: (id: string) => void;
}
/**
@@ -27,7 +34,10 @@ interface DashboardGridProps {
* coord change (gridstack already moved the item; the coord round-trips back
* through `onChange` → state and matches what gridstack has).
*/
-export function DashboardGrid({ blocks, editing, cols, onChange, renderWidget }: DashboardGridProps) {
+export function DashboardGrid({
+ blocks, editing, cols, onChange, renderWidget,
+ labelFor, configurableIds, onToggleVisible, onConfigOpen,
+}: DashboardGridProps) {
const elRef = useRef(null);
const gridRef = useRef(null);
const [contentEls, setContentEls] = useState>({});
@@ -53,7 +63,11 @@ export function DashboardGrid({ blocks, editing, cols, onChange, renderWidget }:
float: true, // free placement — items stay where dropped (no auto-compact)
disableDrag: !editing,
disableResize: !editing,
- handle: '.grid-stack-item-content',
+ // Default handle (.grid-stack-item-content) = the whole card is a drag
+ // target in edit mode — forgiving + discoverable. The card body is
+ // pointer-events-none in edit mode so widget controls don't fire, and
+ // the eye/gear are s which gridstack's skipMouseDown excludes
+ // from dragging. The overlay's grip + "拖动" label is the visual cue.
},
host,
);
@@ -94,16 +108,55 @@ export function DashboardGrid({ blocks, editing, cols, onChange, renderWidget }:
return (
- {blocks.map((b) =>
- contentEls[b.id]
- ? createPortal(
-
- {renderWidget(b)}
-
,
- contentEls[b.id],
- )
- : null,
- )}
+ {blocks.map((b) => {
+ const target = contentEls[b.id];
+ if (!target) return null;
+ const hidden = editing && !b.visible;
+ return createPortal(
+
+ {editing && (
+
+
+ 拖动
+
+ {configurableIds.has(b.id) && b.visible && (
+
onConfigOpen(b.id)}
+ title="设置"
+ aria-label="设置"
+ className="inline-flex size-6 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
+ >
+
+
+ )}
+
onToggleVisible(b.id)}
+ title={b.visible ? '隐藏' : '显示'}
+ aria-label={b.visible ? '隐藏' : '显示'}
+ className="inline-flex size-6 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
+ >
+ {b.visible ? : }
+
+
+ )}
+ {hidden ? (
+
+ {labelFor(b.id)} · 已隐藏
+
+ ) : (
+
+ {renderWidget(b)}
+
+ )}
+
,
+ target,
+ );
+ })}
);
}
diff --git a/packages/webui/src/components/pages/overview-layout-editor.tsx b/packages/webui/src/components/pages/overview-layout-editor.tsx
deleted file mode 100644
index 5215d31c..00000000
--- a/packages/webui/src/components/pages/overview-layout-editor.tsx
+++ /dev/null
@@ -1,244 +0,0 @@
-import { useMemo, useState } from 'react';
-import { Reorder } from 'motion/react';
-import { Check, Eye, EyeOff, GripVertical, Lock, RotateCcw, Settings2 } from 'lucide-react';
-import { Button } from '@/components/ui/button';
-import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
-import { Input } from '@/components/ui/input';
-import { cn } from '@/lib/utils';
-import {
- ALL_LOG_LEVELS, CONFIGURABLE_WIDGETS, parseAlertsConfig, parseSessionsConfig,
-} from '@/lib/dashboard-layout';
-import type { UiLayoutItem } from '@/types';
-
-type SortOpt = 'recent' | 'uin' | 'nickname';
-const SORT_LABELS: Record = { recent: '最近', uin: 'QQ 号', nickname: '昵称' };
-
-// Edit panel for the overview's "编辑布局" mode. Overview-card POSITION/SIZE is
-// edited in place on the gridstack grid below; this panel only toggles which
-// cards are shown, and (re)orders the sidebar nav (a 1-D list, so it keeps the
-// motion Reorder drag from phase 3). Pinned nav items can't be hidden.
-
-// ── widget visibility (no drag — grid owns position) ──
-
-function AlertsConfigForm({ config, onChange }: { config: Record | undefined; onChange: (c: Record) => void }) {
- const c = parseAlertsConfig(config);
- return (
-
-
- 显示条数
- onChange({ count: Math.min(50, Math.max(1, Math.trunc(Number(e.target.value) || 1))) })}
- className="h-8 w-20"
- />
-
-
-
级别
-
- {ALL_LOG_LEVELS.map((lv) => {
- const on = c.levels.includes(lv);
- return (
- {
- const next = on ? c.levels.filter((x) => x !== lv) : [...c.levels, lv];
- if (next.length > 0) onChange({ levels: next });
- }}
- className={cn(
- 'rounded-md border px-2 py-1 text-[11px] uppercase transition-colors cursor-pointer',
- on ? 'border-primary bg-primary/10 text-primary' : 'border-border text-muted-foreground hover:bg-accent/40',
- )}
- >
- {lv}
-
- );
- })}
-
-
-
- );
-}
-
-function SessionsConfigForm({ config, onChange }: { config: Record | undefined; onChange: (c: Record) => void }) {
- const c = parseSessionsConfig(config);
- return (
-
-
-
排序
-
- {(['recent', 'uin', 'nickname'] as SortOpt[]).map((s) => (
- onChange({ sort: s })}
- className={cn(
- 'rounded-md border px-2 py-1 text-[11px] transition-colors cursor-pointer',
- c.sort === s ? 'border-primary bg-primary/10 text-primary' : 'border-border text-muted-foreground hover:bg-accent/40',
- )}
- >
- {SORT_LABELS[s]}
-
- ))}
-
-
-
- 筛选(昵称 / QQ 号)
- onChange({ filter: e.target.value })} className="h-8" />
-
-
- );
-}
-
-function VisibilityList({
- items, labelFor, onToggle, onConfig,
-}: {
- items: UiLayoutItem[];
- labelFor: (id: string) => string;
- onToggle: (id: string) => void;
- onConfig: (id: string, config: Record) => void;
-}) {
- const [open, setOpen] = useState(null);
- return (
-
- {items.map((item) => {
- const configurable = CONFIGURABLE_WIDGETS.has(item.id);
- const isOpen = open === item.id;
- return (
-
-
- {labelFor(item.id)}
- {configurable && (
- setOpen(isOpen ? null : item.id)}
- title="设置"
- aria-label="设置"
- className={cn(
- 'inline-flex size-8 cursor-pointer items-center justify-center rounded-md transition-colors hover:bg-accent/40',
- isOpen ? 'text-primary' : 'text-muted-foreground hover:text-foreground',
- )}
- >
-
-
- )}
- onToggle(item.id)}
- title={item.visible ? '隐藏' : '显示'}
- aria-label={item.visible ? '隐藏' : '显示'}
- className="inline-flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent/40 hover:text-foreground"
- >
- {item.visible ? : }
-
-
- {configurable && isOpen && (
- item.id === 'alerts'
- ?
onConfig('alerts', c)} />
- : onConfig('sessions', c)} />
- )}
-
- );
- })}
-
- );
-}
-
-// ── nav reorder + visibility (1-D list, motion drag) ──
-
-function NavReorderList({
- items, labelFor, pinned, onChange,
-}: { items: UiLayoutItem[]; labelFor: (id: string) => string; pinned: readonly string[]; onChange: (items: UiLayoutItem[]) => void }) {
- const ids = useMemo(() => items.map((i) => i.id), [items]);
- const byId = useMemo(() => new Map(items.map((i) => [i.id, i])), [items]);
-
- const reorder = (newIds: string[]) =>
- onChange(newIds.map((id) => byId.get(id)).filter((x): x is UiLayoutItem => !!x));
- const toggle = (id: string) =>
- onChange(items.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i)));
-
- return (
-
- {ids.map((id) => {
- const item = byId.get(id);
- if (!item) return null;
- const isPinned = pinned.includes(id);
- return (
-
-
- {labelFor(id)}
- {isPinned ? (
-
-
-
- ) : (
- toggle(id)}
- title={item.visible ? '隐藏' : '显示'}
- aria-label={item.visible ? '隐藏' : '显示'}
- className="inline-flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent/40 hover:text-foreground"
- >
- {item.visible ? : }
-
- )}
-
- );
- })}
-
- );
-}
-
-export interface LayoutEditorProps {
- blocks: UiLayoutItem[];
- blockLabelFor: (id: string) => string;
- navItems: UiLayoutItem[];
- navLabelFor: (id: string) => string;
- navPinned: readonly string[];
- onToggleBlock: (id: string) => void;
- onBlockConfig: (id: string, config: Record) => void;
- onNav: (items: UiLayoutItem[]) => void;
- onReset: () => void;
- onDone: () => void;
-}
-
-export function LayoutEditor({
- blocks, blockLabelFor, navItems, navLabelFor, navPinned, onToggleBlock, onBlockConfig, onNav, onReset, onDone,
-}: LayoutEditorProps) {
- return (
-
-
-
- 编辑布局
- 在下方网格直接拖动卡片、拖角缩放;这里控制卡片显隐与导航。改动自动保存。
-
-
-
- 恢复默认
-
-
- 完成
-
-
-
-
-
-
-
-
- );
-}
diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx
index a2c2c3ad..4c9d3f24 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 } from 'motion/react';
import { Link } from '@tanstack/react-router';
import {
- Activity, ArrowRight, Bell, Cable, Cpu, MemoryStick, MonitorCog, Pencil, PlugZap,
- RefreshCw, Server, Users,
+ Activity, ArrowRight, Bell, Cable, Check, Cpu, MemoryStick, MonitorCog, Pencil, PlugZap,
+ RefreshCw, RotateCcw, Server, Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
@@ -18,22 +18,20 @@ import { useApi } from '@/lib/api';
import { useAppState } from '@/contexts/AppStateContext';
import { useSession } from '@/contexts/SessionContext';
import { useTheme } from '@/contexts/ThemeContext';
-import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
+import { useLayout } from '@/contexts/LayoutContext';
import { useMediaQuery } from '@/hooks/use-media-query';
import {
- GRID_COLS, parseAlertsConfig, parseSessionsConfig, widgetLabel,
+ CONFIGURABLE_WIDGETS, GRID_COLS, parseAlertsConfig, parseSessionsConfig, widgetLabel,
type AlertsConfig, type SessionsConfig,
} from '@/lib/dashboard-layout';
-import { NAV_ITEMS, PINNED_NAV } from '@/components/layout/sidebar';
+import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { DashboardGrid, type GridCoord } from '@/components/pages/dashboard-grid';
-import { LayoutEditor } from '@/components/pages/overview-layout-editor';
+import { AlertsConfigForm, SessionsConfigForm } from '@/components/pages/widget-config-forms';
function qqAvatarUrl(uin: string) {
return `/avatar/${encodeURIComponent(uin)}`;
}
-const navLabelFor = (id: string) => NAV_ITEMS.find((n) => n.to === id)?.label ?? id;
-
function renderWidget(block: UiLayoutItem): ReactNode {
if (block.id.startsWith('stat:')) return ;
switch (block.id) {
@@ -47,16 +45,15 @@ function renderWidget(block: UiLayoutItem): ReactNode {
export function OverviewPage() {
const { qqList, processList } = useAppState();
- const { overviewBlocks, navItems, setOverviewBlocks, setNavItems, resetLayout } = useLayout();
+ const { overviewBlocks, setOverviewBlocks, resetLayout, editing: editingCtx, setEditing } = useLayout();
const isWide = useMediaQuery('(min-width: 768px)');
- const [editingOn, setEditingOn] = useState(false);
- const editing = isWide && editingOn;
+ // Free-grid editing is desktop-only (no room to drag/resize on a phone).
+ const editing = isWide && editingCtx;
+ const [configId, setConfigId] = useState(null);
const visibleBlocks = useMemo(() => overviewBlocks.filter((b) => b.visible), [overviewBlocks]);
- const nav = useMemo(
- () => reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV),
- [navItems],
- );
+ // In edit mode show ALL blocks (hidden ones as re-enableable ghosts); else visible-only.
+ const gridBlocks = editing ? overviewBlocks : visibleBlocks;
const onGridChange = (coords: GridCoord[]) => {
const cmap = new Map(coords.map((c) => [c.id, c]));
@@ -75,31 +72,30 @@ export function OverviewPage() {
setOverviewBlocks(overviewBlocks.map((b) => (b.id === id ? { ...b, config: { ...b.config, ...config } } : b)));
const loadableProcs = processList.filter((p) => !p.injected).length;
+ const configBlock = configId ? overviewBlocks.find((b) => b.id === configId) : null;
return (
- {/* Toolbar: edit toggle is desktop-only (free grid needs room to drag). */}
- {isWide && !editing && (
-
-
setEditingOn(true)}>
- 编辑布局
+ {/* Toolbar: edit toggle is desktop-only. In edit mode the cards carry
+ their own floating drag/hide/settings overlays, and the sidebar nav
+ becomes drag-sortable — no separate editor panel. */}
+ {isWide && (
+
+ {editing && (
+
+ 恢复默认
+
+ )}
+
setEditing(!editingCtx)}>
+ {editing ? <> 完成> : <> 编辑布局>}
)}
{editing && (
- setEditingOn(false)}
- />
+
+ 拖动卡片顶部的「拖动」手柄移动位置、拖右下角缩放;眼睛图标显隐、齿轮改设置。左侧导航也可在编辑态拖动排序。
+
)}
{/* First-run nudge — always shown (not a grid widget) so it can't be hidden. */}
@@ -125,17 +121,31 @@ export function OverviewPage() {
)}
- {visibleBlocks.length === 0 ? (
+ {visibleBlocks.length === 0 && !editing ? (
) : (
)}
+
+ { if (!o) setConfigId(null); }}>
+
+
+ {configBlock ? `${widgetLabel(configBlock.id)} · 设置` : '设置'}
+
+ {configBlock?.id === 'alerts' && setBlockConfig('alerts', c)} />}
+ {configBlock?.id === 'sessions' && setBlockConfig('sessions', c)} />}
+
+
);
}
@@ -163,19 +173,19 @@ function StatTile({
to?: AppPath;
}) {
const body = (
-
+
{icon}
-
{label}
-
{value}
- {subtext &&
{subtext}
}
+
{label}
+
{value}
+ {subtext &&
{subtext}
}
{to && }
diff --git a/packages/webui/src/components/pages/widget-config-forms.tsx b/packages/webui/src/components/pages/widget-config-forms.tsx
new file mode 100644
index 00000000..bc53d222
--- /dev/null
+++ b/packages/webui/src/components/pages/widget-config-forms.tsx
@@ -0,0 +1,85 @@
+import { Input } from '@/components/ui/input';
+import { cn } from '@/lib/utils';
+import { ALL_LOG_LEVELS, parseAlertsConfig, parseSessionsConfig } from '@/lib/dashboard-layout';
+
+// 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.
+
+type SortOpt = 'recent' | 'uin' | 'nickname';
+const SORT_LABELS: Record = { recent: '最近', uin: 'QQ 号', nickname: '昵称' };
+
+interface FormProps {
+ config: Record | undefined;
+ onChange: (c: Record) => void;
+}
+
+export function AlertsConfigForm({ config, onChange }: FormProps) {
+ const c = parseAlertsConfig(config);
+ return (
+
+
+ 显示条数
+ onChange({ count: Math.min(50, Math.max(1, Math.trunc(Number(e.target.value) || 1))) })}
+ className="h-8 w-24"
+ />
+
+
+
显示级别
+
+ {ALL_LOG_LEVELS.map((lv) => {
+ const on = c.levels.includes(lv);
+ return (
+ {
+ const next = on ? c.levels.filter((x) => x !== lv) : [...c.levels, lv];
+ if (next.length > 0) onChange({ levels: next });
+ }}
+ className={cn(
+ 'rounded-md border px-2.5 py-1 text-xs uppercase transition-colors cursor-pointer',
+ on ? 'border-primary bg-primary/10 text-primary' : 'border-border text-muted-foreground hover:bg-accent/40',
+ )}
+ >
+ {lv}
+
+ );
+ })}
+
+
+
+ );
+}
+
+export function SessionsConfigForm({ config, onChange }: FormProps) {
+ const c = parseSessionsConfig(config);
+ return (
+
+
+
排序
+
+ {(['recent', 'uin', 'nickname'] as SortOpt[]).map((s) => (
+ onChange({ sort: s })}
+ className={cn(
+ 'rounded-md border px-2.5 py-1 text-xs transition-colors cursor-pointer',
+ c.sort === s ? 'border-primary bg-primary/10 text-primary' : 'border-border text-muted-foreground hover:bg-accent/40',
+ )}
+ >
+ {SORT_LABELS[s]}
+
+ ))}
+
+
+
+ 筛选(昵称 / QQ 号)
+ onChange({ filter: e.target.value })} className="h-8" />
+
+
+ );
+}
diff --git a/packages/webui/src/contexts/LayoutContext.tsx b/packages/webui/src/contexts/LayoutContext.tsx
index aca4dbfc..57a07fe0 100644
--- a/packages/webui/src/contexts/LayoutContext.tsx
+++ b/packages/webui/src/contexts/LayoutContext.tsx
@@ -79,6 +79,10 @@ interface LayoutContextValue {
setPages: (patch: Partial) => void;
/** True once the authed config load has resolved (gates the default-route redirect). */
ready: boolean;
+ /** Shared "编辑布局" mode — the dashboard grid AND the sidebar read this so both
+ * show in-place edit affordances from a single toggle. */
+ editing: boolean;
+ setEditing: (v: boolean) => void;
}
const LayoutContext = createContext(null);
@@ -88,6 +92,7 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
const [layout, setLayout] = useState(DEFAULT_LAYOUT);
const [pages, setPagesState] = useState(DEFAULT_PAGES);
const [ready, setReady] = useState(false);
+ const [editing, setEditing] = useState(false);
const layoutRef = useRef(layout);
const pagesRef = useRef(pages);
// Set once the user edits, so the initial GET (which may resolve AFTER the
@@ -186,7 +191,9 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
pages,
setPages,
ready,
- }), [layout, setOverviewBlocks, setNavItems, resetLayout, pages, setPages, ready]);
+ editing,
+ setEditing,
+ }), [layout, setOverviewBlocks, setNavItems, resetLayout, pages, setPages, ready, editing]);
return {children} ;
}
diff --git a/packages/webui/src/index.css b/packages/webui/src/index.css
index f1d4f1f8..7559510c 100644
--- a/packages/webui/src/index.css
+++ b/packages/webui/src/index.css
@@ -238,12 +238,21 @@ html[data-reduce-motion="1"] *::after {
background: color-mix(in oklab, var(--primary) 8%, transparent);
border-radius: var(--radius);
}
-/* Resize handle — only meaningful while editing (grid is interactive). */
-.grid-stack-item > .ui-resizable-handle {
- filter: none;
-}
+/* Resize handle — only present while editing (grid is interactive). Make the
+ bottom-right grip obvious so it's clearly draggable. */
.grid-stack-item > .ui-resizable-se {
- /* Make the bottom-right resize grip visible against either theme. */
- border-right: 2px solid color-mix(in oklab, var(--primary) 70%, transparent);
- border-bottom: 2px solid color-mix(in oklab, var(--primary) 70%, transparent);
+ width: 18px;
+ height: 18px;
+ right: 5px;
+ bottom: 5px;
+ background-image: none;
+ transform: none;
+ border-right: 3px solid var(--primary);
+ border-bottom: 3px solid var(--primary);
+ border-bottom-right-radius: 5px;
+ opacity: 0.65;
+ z-index: 30;
+}
+.grid-stack-item:hover > .ui-resizable-se {
+ opacity: 1;
}