From f73ad988b67dfb8dad9bc82afcc15b517f91afd3 Mon Sep 17 00:00:00 2001 From: qinjian Date: Mon, 29 Sep 2025 16:59:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sections/wuyuanbiaoba/container/index.jsx | 20 ++++++++++++------- package.json | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/client/src/sections/wuyuanbiaoba/container/index.jsx b/client/src/sections/wuyuanbiaoba/container/index.jsx index d3fe5de..5d02741 100644 --- a/client/src/sections/wuyuanbiaoba/container/index.jsx +++ b/client/src/sections/wuyuanbiaoba/container/index.jsx @@ -29,10 +29,12 @@ const WuyuanbiaobaContent = () => { const realtimeDataSubscription = useWebSocketSubscription("dev", "data"); const realtimeBufferRef = useRef([]); const exportCountRef = useRef(200); - // 设置导出数据条数 + const MAX_BUFFER_SIZE = 1000; + const setExportCount = (count) => { exportCountRef.current = count; }; + // 数据缓冲区数据维护函数 const pushToRealtimeBuffer = (newDataGroup) => { // newDataGroup: { time: "2025-09-29 01:40:57.091", data: [...] } @@ -45,9 +47,11 @@ const WuyuanbiaobaContent = () => { // 合并到缓冲区 realtimeBufferRef.current = [...realtimeBufferRef.current, group]; - // 只保留最近200条数据 - if (realtimeBufferRef.current.length > exportCountRef.current) { - realtimeBufferRef.current = realtimeBufferRef.current.slice(-exportCountRef.current); + // 只保留最大MAX_BUFFER_SIZE条数据 + if (realtimeBufferRef.current.length > MAX_BUFFER_SIZE) { + realtimeBufferRef.current = realtimeBufferRef.current.slice( + -MAX_BUFFER_SIZE + ); } }; const { @@ -200,12 +204,14 @@ const WuyuanbiaobaContent = () => { }, [realtimeDataSubscription.latest]); const dataExport = async () => { - const dataToExport = realtimeBufferRef.current; - if (dataToExport.length === 0) { + const count = exportCountRef.current || 200; + const buf = realtimeBufferRef.current; + if (buf.length === 0) { console.warn("没有数据可导出"); return; } - // console.log('导出数据:', dataToExport); + // 只取最新的 count 条 + const dataToExport = buf.slice(-count); // 收集所有出现过的desc,保持顺序且唯一 const descSet = []; diff --git a/package.json b/package.json index 34e27e4..90c8fe3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wuyuanbiaoba-web", - "version": "1.0.1", + "version": "1.0.2", "main": "index.html", "scripts": { "test": "echo \"Error: no test specified\" && exit 1",