From 20a69a25bc7b8b7d1b065c81d8a39115386e35e3 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Sun, 14 Dec 2025 01:51:23 +0800 Subject: [PATCH] feat:log update --- src/pages/LogsPage.tsx | 36 +++++++++++++++++++++++++++++++++++- src/styles/components.scss | 14 ++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/pages/LogsPage.tsx b/src/pages/LogsPage.tsx index 87d0ab3..ddc71d1 100644 --- a/src/pages/LogsPage.tsx +++ b/src/pages/LogsPage.tsx @@ -27,11 +27,28 @@ export function LogsPage() { const [errorLogs, setErrorLogs] = useState([]); const [loadingErrors, setLoadingErrors] = useState(false); + const logViewerRef = useRef(null); + const pendingScrollToBottomRef = useRef(false); + // 保存最新时间戳用于增量获取 const latestTimestampRef = useRef(0); const disableControls = connectionStatus !== 'connected'; + const isNearBottom = (node: HTMLPreElement | null) => { + if (!node) return true; + const threshold = 24; + return node.scrollHeight - node.scrollTop - node.clientHeight <= threshold; + }; + + const scrollToBottom = () => { + const node = logViewerRef.current; + if (!node) return; + node.scrollTop = node.scrollHeight; + }; + + const isWarningLine = (line: string) => /\bwarn(?:ing)?\b/i.test(line) || line.includes('警告'); + const loadLogs = async (incremental = false) => { if (connectionStatus !== 'connected') { setLoading(false); @@ -44,6 +61,8 @@ export function LogsPage() { setError(''); try { + pendingScrollToBottomRef.current = !incremental || isNearBottom(logViewerRef.current); + const params = incremental && latestTimestampRef.current > 0 ? { after: latestTimestampRef.current } : {}; @@ -166,6 +185,15 @@ export function LogsPage() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [autoRefresh, connectionStatus]); + useEffect(() => { + if (!pendingScrollToBottomRef.current) return; + if (loading) return; + if (!logViewerRef.current) return; + + scrollToBottom(); + pendingScrollToBottomRef.current = false; + }, [loading, logLines]); + const logsText = logLines.join('\n'); return ( @@ -193,7 +221,13 @@ export function LogsPage() { {loading ? (
{t('logs.loading')}
) : logsText ? ( -
{logsText}
+
+            {logLines.map((line, index) => (
+              
+                {line}
+              
+            ))}
+          
) : ( )} diff --git a/src/styles/components.scss b/src/styles/components.scss index 9d5208f..78e6948 100644 --- a/src/styles/components.scss +++ b/src/styles/components.scss @@ -615,6 +615,20 @@ textarea { color: var(--text-primary); } +.log-viewer-lines { + .log-line { + display: block; + padding: 1px 0; + } + + .log-line-warning { + color: var(--warning-text, #92400e); + background: var(--warning-bg, rgba(251, 191, 36, 0.18)); + border-radius: 4px; + padding: 2px 6px; + } +} + .hint { color: var(--text-secondary); }