From 521cbe41077f07cb6d567573894bd4ddff2bb621 Mon Sep 17 00:00:00 2001 From: wangfq Date: Mon, 15 Jun 2026 10:02:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20edc-web=20=E6=94=AF=E6=8C=81=E8=BD=A6?= =?UTF-8?q?=E6=A3=80=E5=99=A8=E5=BA=8F=E5=88=97=E5=8F=B7=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E4=B8=8E=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 自动化测试区域新增「车检器序列号」输入框 - 回车键自动触发「开始」按钮 - /api/automation/start 接收 detector_serial,写入 tb_pending_detector - 测试操作页 + 测试信息页(全部/B2/B4)显示序列号,空时显示 '-' - 页面加载和测试结束后焦点自动回到序列号输入框(全选),方便连续测试 --- edc-web/app/models.py | 18 ++++++++++++++ edc-web/app/routes/test_op.py | 6 +++++ edc-web/app/static/js/test_data.js | 3 +++ edc-web/app/static/js/test_op.js | 39 ++++++++++++++++++++++++++++-- edc-web/app/templates/test_op.html | 11 ++++++--- edc_server | 2 +- 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/edc-web/app/models.py b/edc-web/app/models.py index bb586bf..42087a3 100644 --- a/edc-web/app/models.py +++ b/edc-web/app/models.py @@ -942,3 +942,21 @@ def delete_device_logs(serial: str = "", event_type: str = "", return cnt finally: conn.close() + + +# ─── tb_pending_detector ─────────────────────────────────────────── + +def set_pending_detector_serial(dnt_id: int, detector_serial: str): + """设置待插入的车检器序列号(UPSERT)""" + conn = get_conn() + try: + with conn.cursor() as cur: + cur.execute( + """INSERT INTO tb_pending_detector (dnt_id, detector_serial) + VALUES (%s, %s) + ON DUPLICATE KEY UPDATE detector_serial = VALUES(detector_serial)""", + (dnt_id, detector_serial), + ) + conn.commit() + finally: + conn.close() diff --git a/edc-web/app/routes/test_op.py b/edc-web/app/routes/test_op.py index bf3b41d..fe805c2 100644 --- a/edc-web/app/routes/test_op.py +++ b/edc-web/app/routes/test_op.py @@ -13,6 +13,7 @@ from app.models import ( get_wave_records, clear_serialnet_records, insert_log, + set_pending_detector_serial, ) bp = Blueprint("test_op", __name__) @@ -89,10 +90,15 @@ def api_automation_start(): data = request.get_json() dnt_id = data.get("dnt_id") count = int(data.get("count", 1)) + detector_serial = (data.get("detector_serial") or "").strip() device = get_device_by_id(dnt_id) target = f"{device['serial']}" if device else f"dnt_id={dnt_id}" + # 存储待插入的车检器序列号 + if detector_serial: + set_pending_detector_serial(dnt_id, detector_serial) + # 清除旧记录,然后插入第一条 0xB0 clear_serialnet_records(dnt_id) record_id = insert_serialnet(dnt_id, COMMANDS["B0"]) diff --git a/edc-web/app/static/js/test_data.js b/edc-web/app/static/js/test_data.js index 6de66fc..0da4251 100644 --- a/edc-web/app/static/js/test_data.js +++ b/edc-web/app/static/js/test_data.js @@ -30,6 +30,7 @@ const VIEWS = { cols: [ { key: 'id', title: 'ID' }, { key: 'serial', title: '设备编码' }, + { key: 'detector_serial', title: '车检器序列号', render: r => r.detector_serial || '-' }, { key: 'model', title: '型号', render: r => getDevTypeName(r.sub_type) }, { key: 'data_source', title: '来源' }, { key: 'test_mode', title: '测试模式', render: r => r.test_mode === 1 ? '波动' : '灵敏度' }, @@ -66,6 +67,7 @@ const VIEWS = { cols: [ { key: 'id', title: 'ID' }, { key: 'serial', title: '设备编码' }, + { key: 'detector_serial', title: '车检器序列号', render: r => r.detector_serial || '-' }, { key: 'model', title: '型号', render: r => getDevTypeName(r.sub_type) }, { key: 'test_mode', title: '测试模式', render: r => r.test_mode === 1 ? '波动' : '灵敏度' }, { key: 'iffinish', title: '完成', render: r => r.iffinish === '1' ? '是' : '否' }, @@ -89,6 +91,7 @@ const VIEWS = { cols: [ { key: 'id', title: 'ID' }, { key: 'serial', title: '设备编码' }, + { key: 'detector_serial', title: '车检器序列号', render: r => r.detector_serial || '-' }, { key: 'remain_count', title: '剩余次数' }, { key: 'work_freq', title: '工作频率(Hz)' }, { key: 'curr_dist', title: '当前距离(mm)' }, diff --git a/edc-web/app/static/js/test_op.js b/edc-web/app/static/js/test_op.js index 82d3f3b..c357b0a 100644 --- a/edc-web/app/static/js/test_op.js +++ b/edc-web/app/static/js/test_op.js @@ -63,9 +63,12 @@ async function toggleAuto() { async function startAuto() { if (!checkDeviceOnline()) return; - const count = parseInt(document.getElementById("test-count").value) || 10; + const count = parseInt(document.getElementById("test-count").value) || 1; if (count < 1) return; + // 读取车检器序列号 + const detectorSerial = document.getElementById("detector-serial").value.trim(); + // 读取参数 intervalMs = (parseFloat(document.getElementById("interval-sec").value) || 3) * 1000; timeoutMs = (parseFloat(document.getElementById("timeout-sec").value) || 10) * 1000; @@ -118,7 +121,7 @@ async function startAuto() { const resp = await fetch("/api/automation/start", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ dnt_id: DNT_ID, count }), + body: JSON.stringify({ dnt_id: DNT_ID, count, detector_serial: detectorSerial }), }); const data = await resp.json(); if (data.ok) { @@ -150,6 +153,9 @@ function stopAuto() { const btn = document.getElementById("btn-auto"); btn.textContent = "开始"; btn.className = "btn-start"; + + // 自动化结束 → 焦点回到车检器序列号输入框(全选),方便下一个车检器测试 + setTimeout(focusDetectorSerial, 100); } // ─── 发送下一条 0xB0 ──────────────────────────── @@ -404,9 +410,37 @@ async function loadInitialData() { } catch (e) { // 初始加载静默失败 } + // 页面加载后焦点落到车检器序列号输入框(全选) + setTimeout(focusDetectorSerial, 200); } loadInitialData(); +// ─── 回车键触发"开始"按钮 ───────────────────── + +/** 将焦点移到车检器序列号输入框并全选已有文本 */ +function focusDetectorSerial() { + const input = document.getElementById("detector-serial"); + if (input) { + input.focus(); + input.select(); + } +} + +document.addEventListener("DOMContentLoaded", function() { + const detectorInput = document.getElementById("detector-serial"); + if (detectorInput) { + detectorInput.addEventListener("keydown", function(e) { + if (e.key === "Enter") { + e.preventDefault(); + const btn = document.getElementById("btn-auto"); + if (btn && !autoRunning) { + btn.click(); + } + } + }); + } +}); + // ─── 设备状态异步刷新 ────────────────────────── async function refreshDeviceStatus() { @@ -543,6 +577,7 @@ function renderLatest(data) { typeName = devTypeNameCache[data.sub_type] || `Unknown(${data.sub_type})`; } div.innerHTML = ` +

车检器序列号:${data.detector_serial || '-'}

设备型号:${typeName || '-'}

测试模式:${data.test_mode === 1 ? '波动测试' : '灵敏度测试'}

峰峰值:${data.ppvalue?.toFixed(2) || '-'} V

diff --git a/edc-web/app/templates/test_op.html b/edc-web/app/templates/test_op.html index 45850c9..a46bf7e 100644 --- a/edc-web/app/templates/test_op.html +++ b/edc-web/app/templates/test_op.html @@ -58,17 +58,22 @@

自动化测试

+ +
diff --git a/edc_server b/edc_server index 6e13990..ff94827 160000 --- a/edc_server +++ b/edc_server @@ -1 +1 @@ -Subproject commit 6e13990386fe364c43d395eab24d2438f845a683 +Subproject commit ff9482780d639863ddc88a11749cd425bbc69712