From f2e9cc9345b2509453de682182599cb0c4d22afb Mon Sep 17 00:00:00 2001 From: wangfq Date: Wed, 10 Jun 2026 13:55:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=9E=E5=9C=A8=E7=BA=BF=E7=8A=B6=E6=80=81=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E5=8F=91=E9=80=81=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 currentDeviceState 变量跟踪设备状态 - refreshDeviceStatus 同步更新 currentDeviceState - sendCmd/manual cmds(B0/B1/BA/BB/BC) 调用前检查在线状态 - startAuto(自动化开始) 调用前检查在线状态 - 非在线时弹窗提示「设备当前状态为「离线/通信不良」,无法发送指令」 --- edc-web/app/static/js/test_op.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/edc-web/app/static/js/test_op.js b/edc-web/app/static/js/test_op.js index 6001a91..04a2d6d 100644 --- a/edc-web/app/static/js/test_op.js +++ b/edc-web/app/static/js/test_op.js @@ -8,6 +8,7 @@ let autoRemaining = 0; let autoStartTime = ""; let localSinceStr = ""; let currentTestMode = null; // 0=灵敏度, 1=波动, null=未加载 +let currentDeviceState = null; // 当前设备状态 (0=离线 1=在线 2=通信不良 null=未加载) let pollInterval = null; let nextCmdTimer = null; // 间隔等待定时器 @@ -18,9 +19,22 @@ let cmdSentAt = 0; // 最近一次发送 0xB0 时间 let intervalMs = 10000; // 默认 10s let timeoutMs = 5000; // 默认 5s +// ─── 设备在线检查 ────────────────────────────── + +function checkDeviceOnline() { + if (currentDeviceState !== 1) { + const stateName = currentDeviceState === 2 ? '通信不良' : + currentDeviceState === 0 ? '离线' : '未知'; + alert(`设备当前状态为「${stateName}」,无法发送指令`); + return false; + } + return true; +} + // ─── 手动指令 ───────────────────────────────── async function sendCmd(cmd) { + if (!checkDeviceOnline()) return; try { const resp = await fetch("/api/command", { method: "POST", @@ -47,6 +61,7 @@ async function toggleAuto() { } async function startAuto() { + if (!checkDeviceOnline()) return; const count = parseInt(document.getElementById("test-count").value) || 10; if (count < 1) return; @@ -309,6 +324,7 @@ async function refreshDeviceStatus() { const resp = await fetch(`/api/devices/${DNT_ID}/status`); const data = await resp.json(); if (data.ok) { + currentDeviceState = data.state; const el = document.getElementById("device-status-text"); if (el) { el.textContent = data.state_name;