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 { Textarea } from '@/components/ui/textarea'; import { cn } from '@/lib/utils'; import { useAppState } from '@/contexts/AppStateContext'; import { 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. 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 (
显示级别
{ALL_LOG_LEVELS.map((lv) => { const on = c.levels.includes(lv); return ( ); })}
); } export function SessionsConfigForm({ config, onChange }: FormProps) { const c = parseSessionsConfig(config); return (
排序
{(['recent', 'uin', 'nickname'] as SortOpt[]).map((s) => ( ))}
); } const HOST_PANELS: { key: 'cpu' | 'memory' | 'runtime'; label: string }[] = [ { key: 'cpu', label: 'CPU 使用率' }, { key: 'memory', label: '内存使用' }, { key: 'runtime', label: '运行进程' }, ]; export function HostConfigForm({ config, onChange }: FormProps) { const c = parseHostConfig(config); return (
显示的指标 {HOST_PANELS.map((p) => ( ))}
); } const CONN_SORTS: { key: 'default' | 'name' | 'status'; label: string }[] = [ { key: 'default', label: '默认' }, { key: 'name', label: '名称' }, { key: 'status', label: '异常优先' }, ]; export function ConnectionsConfigForm({ config, onChange }: FormProps) { const c = parseConnectionsConfig(config); return (
排序
{CONN_SORTS.map((s) => ( ))}
); } export function NoteConfigForm({ config, onChange }: FormProps) { const c = parseNoteConfig(config); return (
便签内容(纯文本,保留换行)