feat: 测试操作页添加被动轮询,实时显示工装本地按键触发的上报数据
- 新增 refreshLatestData() 每 5 秒轮询最新测试数据(不传 since 参数) - lastLatestId/lastWaveId 跟踪最新记录,避免重复渲染 - 自动化运行中跳过被动轮询,避免与 pollProgress 冲突 - pollProgress 同步更新跟踪 ID,自动化结束后无缝衔接
This commit is contained in:
@@ -218,9 +218,9 @@ async function pollProgress() {
|
||||
const stats = data.stats;
|
||||
|
||||
// ── 先渲染数据(放在所有 return 之前,避免完成时跳过渲染)──
|
||||
try { if (data.latest) renderLatest(data.latest); } catch (e) { console.error("renderLatest:", e); }
|
||||
try { if (data.latest) { renderLatest(data.latest); lastLatestId = data.latest.id; } } catch (e) { console.error("renderLatest:", e); }
|
||||
try { if (data.averages) renderAverages(data.averages); } catch (e) { console.error("renderAverages:", e); }
|
||||
try { if (data.latest_wave) renderLatestWave(data.latest_wave); } catch (e) { console.error("renderLatestWave:", e); }
|
||||
try { if (data.latest_wave) { renderLatestWave(data.latest_wave); lastWaveId = data.latest_wave.id; } } catch (e) { console.error("renderLatestWave:", e); }
|
||||
try { if (data.records && data.records.length) renderRecords(data.records); } catch (e) { console.error("renderRecords:", e); }
|
||||
|
||||
// 更新计数
|
||||
@@ -389,8 +389,8 @@ async function loadInitialData() {
|
||||
try {
|
||||
const resp = await fetch(`/api/automation/${DNT_ID}/progress`);
|
||||
const data = await resp.json();
|
||||
if (data.latest) renderLatest(data.latest);
|
||||
if (data.latest_wave) renderLatestWave(data.latest_wave);
|
||||
if (data.latest) { renderLatest(data.latest); lastLatestId = data.latest.id; }
|
||||
if (data.latest_wave) { renderLatestWave(data.latest_wave); lastWaveId = data.latest_wave.id; }
|
||||
} catch (e) {
|
||||
// 初始加载静默失败
|
||||
}
|
||||
@@ -422,11 +422,34 @@ async function refreshDeviceStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
// 每 5 秒刷新设备状态 + 测试模式 + 型号名称缓存(工装页修改后能及时同步)
|
||||
// ─── 被动轮询:实时显示上报数据(工装本地按键 / 网页手动指令触发)───
|
||||
|
||||
let lastLatestId = 0; // 最新测试数据 ID,用于判断是否有新数据
|
||||
let lastWaveId = 0; // 最新波动数据 ID
|
||||
|
||||
async function refreshLatestData() {
|
||||
// 自动化运行中由 pollProgress 负责渲染,避免冲突
|
||||
if (autoRunning) return;
|
||||
try {
|
||||
const resp = await fetch(`/api/automation/${DNT_ID}/progress`);
|
||||
const data = await resp.json();
|
||||
if (data.latest && data.latest.id !== lastLatestId) {
|
||||
lastLatestId = data.latest.id;
|
||||
renderLatest(data.latest);
|
||||
}
|
||||
if (data.latest_wave && data.latest_wave.id !== lastWaveId) {
|
||||
lastWaveId = data.latest_wave.id;
|
||||
renderLatestWave(data.latest_wave);
|
||||
}
|
||||
} catch (e) { /* 静默失败 */ }
|
||||
}
|
||||
|
||||
// 每 5 秒刷新设备状态 + 测试模式 + 型号名称缓存 + 最新测试数据
|
||||
async function refreshAll() {
|
||||
await loadDeviceTypeNames();
|
||||
await loadTestMode();
|
||||
refreshDeviceStatus();
|
||||
refreshLatestData(); // 不 await,避免阻塞
|
||||
}
|
||||
setInterval(refreshAll, 5000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user