From ef267721fd908656c838e0a7218867aea48db6b9 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Tue, 22 Jul 2025 01:48:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=A4=BA=E6=B3=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Oscilloscope/OscilloscopeManager.ts | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/Oscilloscope/OscilloscopeManager.ts b/src/components/Oscilloscope/OscilloscopeManager.ts index aa32fd4..3ad528e 100644 --- a/src/components/Oscilloscope/OscilloscopeManager.ts +++ b/src/components/Oscilloscope/OscilloscopeManager.ts @@ -119,6 +119,27 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() = } }; + // 定时器引用 + let refreshIntervalId: number | undefined; + // 刷新间隔(毫秒),可根据需要调整 + const refreshIntervalMs = ref(1000); + + // 定时刷新函数 + const startAutoRefresh = () => { + if (refreshIntervalId !== undefined) return; + refreshIntervalId = window.setInterval(async () => { + await refreshRAM(); + await getOscilloscopeData(); + }, refreshIntervalMs.value); + }; + + const stopAutoRefresh = () => { + if (refreshIntervalId !== undefined) { + clearInterval(refreshIntervalId); + refreshIntervalId = undefined; + } + }; + // 启动捕获 const startCapture = async () => { if (operationMutex.isLocked()) { @@ -133,12 +154,12 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() = if (!started) throw new Error("无法启动捕获"); alert.info("开始捕获...", 2000); - // 简单轮询,直到捕获完成(可根据后端实际情况优化) - await new Promise((resolve) => setTimeout(resolve, 1000)); - await getOscilloscopeData(); - alert.success("捕获完成", 2000); + // 启动定时刷新 + startAutoRefresh(); } catch (error) { alert.error("捕获失败", 3000); + isCapturing.value = false; + stopAutoRefresh(); } finally { isCapturing.value = false; release(); @@ -248,6 +269,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() = isOperationInProgress, sampleCount, samplePeriodNs, + refreshIntervalMs, applyConfiguration, resetConfiguration,