From 86a43d3006c8da00de9e40633cb3bc1b5b2b16e4 Mon Sep 17 00:00:00 2001 From: jialin Date: Sat, 14 Sep 2024 22:13:32 +0800 Subject: [PATCH] chore: auto scroll --- config/config.ts | 2 +- src/components/logs-viewer/index.tsx | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/config.ts b/config/config.ts index 36546891..9dbc3ccd 100644 --- a/config/config.ts +++ b/config/config.ts @@ -14,7 +14,7 @@ const isProduction = env === 'production'; const t = Date.now(); export default defineConfig({ proxy: { - ...proxy() + ...proxy('http://192.168.50.166:8080') }, history: { type: 'hash' diff --git a/src/components/logs-viewer/index.tsx b/src/components/logs-viewer/index.tsx index 594db0ac..cd928c17 100644 --- a/src/components/logs-viewer/index.tsx +++ b/src/components/logs-viewer/index.tsx @@ -4,7 +4,7 @@ import { Terminal } from '@xterm/xterm'; import '@xterm/xterm/css/xterm.css'; import classNames from 'classnames'; import _ from 'lodash'; -import { memo, useCallback, useEffect, useRef } from 'react'; +import { memo, useCallback, useEffect, useRef, useState } from 'react'; import './index.less'; import useSize from './use-size'; @@ -23,8 +23,13 @@ const LogsViewer: React.FC = (props) => { const termwrapRef = useRef({}); const fitAddonRef = useRef({}); const cacheDataRef = useRef(null); + const [logs, setLogs] = useState(''); const size = useSize(scroller); + const throttleScroll = _.debounce(() => { + termRef.current?.scrollToBottom?.(); + }, 100); + const updateContent = useCallback( _.throttle((data: string) => { cacheDataRef.current = ''; @@ -73,10 +78,9 @@ const LogsViewer: React.FC = (props) => { termRef.current.open(termwrapRef.current); // add event - - termRef.current.onWriteParsed((e: any) => { + termRef.current.onLineFeed((e: any) => { if (cacheDataRef.current) { - termRef.current?.scrollToBottom(); + throttleScroll(); } }); };