fix: relay_out 调整仅改后端格式化,前端直接显示 DB relay_out 字段
- relay_code 保持原始 int 值不变 - decode_relay_info 输出新格式: '存在继电器有输出,脉冲继电器无输出' - 前端不再 JS 端重新解码 relay_code,直接显示 DB 中的 relay_out 字段 - 保留 RELAY_MAP/decodeRelay 作为降级方案(relay_out 为空时用)
This commit is contained in:
@@ -388,12 +388,15 @@ function fmtTime(v) {
|
||||
return `${y}-${m}-${d2} ${h}:${min}:${s}`;
|
||||
}
|
||||
|
||||
const RELAY_MAP = {
|
||||
0: '无输出',
|
||||
1: '存在信号',
|
||||
2: '脉冲信号',
|
||||
3: '存在信号; 脉冲信号',
|
||||
};
|
||||
function decodeRelay(v) {
|
||||
if (v === null || v === undefined || v === '') return '-';
|
||||
const code = parseInt(v);
|
||||
const exist = (code & 0x01) ? "存在继电器有输出" : "存在继电器无输出";
|
||||
const pulse = (code & 0x02) ? "脉冲继电器有输出" : "脉冲继电器无输出";
|
||||
return `${exist},${pulse}`;
|
||||
return RELAY_MAP[parseInt(v)] || `0x${parseInt(v).toString(16).toUpperCase().padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
// ─── 显示最新结果 ──────────────────────────────
|
||||
@@ -413,7 +416,7 @@ function renderLatest(data) {
|
||||
<p>离开速度:${toSpeed(data.exit_speed)} m/s</p>
|
||||
<p>是否完成:${data.iffinish === '1' ? '是' : '否'}</p>
|
||||
<p>故障信息:${data.fault_info || '无'}</p>
|
||||
<p>继电器:${decodeRelay(data.relay_code)}</p>
|
||||
<p>继电器:${data.relay_out || decodeRelay(data.relay_code)}</p>
|
||||
<p>时间:${fmtTime(data.create_time)}</p>
|
||||
`;
|
||||
}
|
||||
@@ -454,7 +457,7 @@ function renderLatestWave(data) {
|
||||
<p>最远距离:${data.far_dist || '-'} mm</p>
|
||||
<p>进入高度 (B4):${data.b4_enter_dist || '-'} mm</p>
|
||||
<p>离开高度 (B4):${data.b4_leave_dist || '-'} mm</p>
|
||||
<p>继电器:${decodeRelay(data.relay_code)}</p>
|
||||
<p>继电器:${data.relay_out || decodeRelay(data.relay_code)}</p>
|
||||
<p>时间:${fmtTime(data.create_time)}</p>
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user