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