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 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 = [];

2
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",

Loading…
Cancel
Save