diff --git a/packages/webui/src/components/pages/logs-page.tsx b/packages/webui/src/components/pages/logs-page.tsx index ac5f9a9d..ee4dd3c7 100644 --- a/packages/webui/src/components/pages/logs-page.tsx +++ b/packages/webui/src/components/pages/logs-page.tsx @@ -1,11 +1,11 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { motion } from 'motion/react'; -import { ArrowDownToLine, Highlighter, Pause, Plus, RefreshCw, Trash2, WrapText, X } from 'lucide-react'; +import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'; +import { motion, AnimatePresence } from 'motion/react'; +import { ArrowDownToLine, Filter, Highlighter, Inbox, Pause, Plus, RefreshCw, Search, SearchX, SlidersHorizontal, Trash2, WrapText, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { ScrollArea } from '@/components/ui/scroll-area'; +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { ConfirmDialog } from '@/components/confirm-dialog'; import { cn } from '@/lib/utils'; import type { LogEntry, LogLevel, UiHighlightRule } from '@/types'; @@ -43,6 +43,39 @@ function matchHighlight(message: string, rules: UiHighlightRule[]): string | nul return null; } +// Apple-style toolbar icon button: icon-only, tooltip-labelled, calm hover. +interface ToolButtonProps { + label: string; + onClick: () => void; + children: ReactNode; + active?: boolean; + danger?: boolean; + disabled?: boolean; +} +function ToolButton({ label, onClick, children, active, danger, disabled }: ToolButtonProps) { + return ( + + + + + {label} + + ); +} + export function LogsPage() { const api = useApi(); const { formatClock } = useTheme(); @@ -55,7 +88,7 @@ export function LogsPage() { const [confirmClear, setConfirmClear] = useState(false); const [serverLevel, setServerLevel] = useState(null); const [levelBusy, setLevelBusy] = useState(false); - const [showHighlights, setShowHighlights] = useState(false); + const [showOptions, setShowOptions] = useState(false); const [newKeyword, setNewKeyword] = useState(''); const [newColor, setNewColor] = useState(HIGHLIGHT_COLORS[0].id); const endRef = useRef(null); @@ -137,6 +170,11 @@ export function LogsPage() { setPages({ logs: { ...prefs, visibleLevels: LEVELS.filter((l) => next.has(l)) } }); }; + const clearFilters = useCallback(() => { + setFilter(''); + setPages({ logs: { ...prefs, visibleLevels: [...LEVELS] } }); + }, [prefs, setPages]); + const addHighlight = () => { const kw = newKeyword.trim(); if (!kw) return; @@ -147,161 +185,282 @@ export function LogsPage() { setPages({ logs: { ...prefs, highlightRules: prefs.highlightRules.filter((_, i) => i !== idx) } }); }; + const live = streamStatus === '实时'; + const connecting = streamStatus === '连接中' || streamStatus === '重连中'; + const levelsFiltered = enabled.size < LEVELS.length; + return ( - - -
- - 运行日志 - {streamStatus} - - 最近 {filtered.length} / {logs.length} 条 · 通过 SSE 推送 + + {/* ── Toolbar ─────────────────────────────────────────────── */} + +
+
+ 运行日志 + + + + {streamStatus} + + +
+ + {filtered.length}/{logs.length} 条 · SSE 实时推送 + {serverLevel && ( + <> + {' · 服务端 '} + {serverLevel.toUpperCase()} + + )} +
-
- setFilter(e.target.value)} - className="h-8 w-48" - /> - - - - - + +
+
+ + setFilter(e.target.value)} + className="h-8 w-44 rounded-lg pl-8 pr-7 sm:w-56" + /> + {filter && ( + + )} +
+ +
+ setPages({ logs: { ...prefs, autoScroll: !prefs.autoScroll } })} + > + {prefs.autoScroll ? : } + + setPages({ logs: { ...prefs, wrap: !prefs.wrap } })} + > + + + setShowOptions((v) => !v)}> + + +
+ + + + void loadLogs()}> + + + setConfirmClear(true)}> + +
- {showHighlights && ( -
-
- setNewKeyword(e.target.value)} - onKeyDown={(e) => { if (e.key === 'Enter') addHighlight(); }} - className="h-8 w-44" - /> -
- {HIGHLIGHT_COLORS.map((c) => ( -
- -
- {prefs.highlightRules.length > 0 && ( -
- {prefs.highlightRules.map((r, i) => ( - - - {r.keyword} - - - ))} -
- )} + {/* ── Level filter (segmented, always visible) ────────────── */} +
+ +
+ {LEVELS.map((lv) => { + const active = enabled.has(lv); + return ( + + ); + })}
- )} - -
- 视图过滤 - {LEVELS.map((lv) => { - const active = enabled.has(lv); - return ( - - ); - })}
-
- - 服务端级别 - - {LEVELS.map((lv) => { - const active = serverLevel === lv; - return ( - - ); - })} -
- - -
- -
- {filtered.length === 0 ? ( -
暂无日志
- ) : ( - filtered.map((log) => { - const hl = matchHighlight(log.message, prefs.highlightRules); - return ( - -
- {formatClock(log.time)} - {log.level.toUpperCase()} - [{log.scope}] - {log.req !== undefined && ( - #{log.req} + {/* ── Options panel (progressive disclosure) ──────────────── */} + + {showOptions && ( + +
+ {/* Server-side level */} +
+
+ 服务端日志级别 + · 仅影响控制台 / 实时流,文件始终落盘 debug +
+
+ {LEVELS.map((lv) => { + const active = serverLevel === lv; + return ( +
- - {log.message} + > + + {lv.toUpperCase()} + + ); + })} +
+
+ + {/* Highlight rules */} +
+
+ + 高亮规则 + · 命中关键词的行会被着色 +
+
+ setNewKeyword(e.target.value)} + onKeyDown={(e) => { if (e.key === 'Enter') addHighlight(); }} + className="h-8 w-44 rounded-lg" + /> +
+ {HIGHLIGHT_COLORS.map((c) => ( +
+ +
+ {prefs.highlightRules.length > 0 && ( +
+ {prefs.highlightRules.map((r, i) => ( + + + {r.keyword} + - - ); - }) + ))} +
+ )} +
+
+
+ )} + + + {/* ── Log stream ──────────────────────────────────────────── */} + +
+ +
+ {filtered.length > 0 && ( +
+ 时间 + 级别 + 模块 + 消息 +
+ )} + + {filtered.length === 0 ? ( +
+ {logs.length === 0 ? ( + <> + + 暂无日志 + + ) : ( + <> + + 没有符合筛选条件的日志 + + + )} +
+ ) : ( +
+ {filtered.map((log) => { + const hl = matchHighlight(log.message, prefs.highlightRules); + return ( + +
+ {formatClock(log.time)} + + + {log.level.toUpperCase()} + + [{log.scope}] +
+ + {log.req !== undefined && ( + #{log.req} + )} + {log.message} + +
+ ); + })} +
)}