feat: edc-web 支持车检器序列号输入与显示

- 自动化测试区域新增「车检器序列号」输入框
- 回车键自动触发「开始」按钮
- /api/automation/start 接收 detector_serial,写入 tb_pending_detector
- 测试操作页 + 测试信息页(全部/B2/B4)显示序列号,空时显示 '-'
- 页面加载和测试结束后焦点自动回到序列号输入框(全选),方便连续测试
This commit is contained in:
wangfq
2026-06-15 10:02:51 +08:00
parent 4ac6cbb2fe
commit 521cbe4107
6 changed files with 73 additions and 6 deletions

View File

@@ -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)' },

View File

@@ -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 = `
<p>车检器序列号:<strong>${data.detector_serial || '-'}</strong></p>
<p>设备型号:<strong>${typeName || '-'}</strong></p>
<p>测试模式:<strong>${data.test_mode === 1 ? '波动测试' : '灵敏度测试'}</strong></p>
<p>峰峰值:${data.ppvalue?.toFixed(2) || '-'} V</p>