Browse Source

fix:数据导出逻辑问题

master
qinjian 2 weeks ago
parent
commit
f73ad988b6
  1. 20
      client/src/sections/wuyuanbiaoba/container/index.jsx
  2. 2
      package.json

20
client/src/sections/wuyuanbiaoba/container/index.jsx

@ -29,10 +29,12 @@ const WuyuanbiaobaContent = () => {
const realtimeDataSubscription = useWebSocketSubscription("dev", "data"); const realtimeDataSubscription = useWebSocketSubscription("dev", "data");
const realtimeBufferRef = useRef([]); const realtimeBufferRef = useRef([]);
const exportCountRef = useRef(200); const exportCountRef = useRef(200);
// const MAX_BUFFER_SIZE = 1000;
const setExportCount = (count) => { const setExportCount = (count) => {
exportCountRef.current = count; exportCountRef.current = count;
}; };
// //
const pushToRealtimeBuffer = (newDataGroup) => { const pushToRealtimeBuffer = (newDataGroup) => {
// newDataGroup: { time: "2025-09-29 01:40:57.091", data: [...] } // newDataGroup: { time: "2025-09-29 01:40:57.091", data: [...] }
@ -45,9 +47,11 @@ const WuyuanbiaobaContent = () => {
// //
realtimeBufferRef.current = [...realtimeBufferRef.current, group]; realtimeBufferRef.current = [...realtimeBufferRef.current, group];
// 200 // MAX_BUFFER_SIZE
if (realtimeBufferRef.current.length > exportCountRef.current) { if (realtimeBufferRef.current.length > MAX_BUFFER_SIZE) {
realtimeBufferRef.current = realtimeBufferRef.current.slice(-exportCountRef.current); realtimeBufferRef.current = realtimeBufferRef.current.slice(
-MAX_BUFFER_SIZE
);
} }
}; };
const { const {
@ -200,12 +204,14 @@ const WuyuanbiaobaContent = () => {
}, [realtimeDataSubscription.latest]); }, [realtimeDataSubscription.latest]);
const dataExport = async () => { const dataExport = async () => {
const dataToExport = realtimeBufferRef.current; const count = exportCountRef.current || 200;
if (dataToExport.length === 0) { const buf = realtimeBufferRef.current;
if (buf.length === 0) {
console.warn("没有数据可导出"); console.warn("没有数据可导出");
return; return;
} }
// console.log(':', dataToExport); // count
const dataToExport = buf.slice(-count);
// desc // desc
const descSet = []; const descSet = [];

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "wuyuanbiaoba-web", "name": "wuyuanbiaoba-web",
"version": "1.0.1", "version": "1.0.2",
"main": "index.html", "main": "index.html",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",

Loading…
Cancel
Save