feat(web-ui): 增强围栏地图交互与接收机状态显示
- 在 geofence-map-adapter.js 中添加了处理围栏顶点和圆心的拖动功能,提升用户交互体验。 - 实现了计算两点间距离的函数,以支持动态调整围栏半径。 - 更新了 receivers.js 中的状态显示逻辑,优化了设备状态的反馈信息,确保更准确的连接状态提示。 - 修改了 CSS 文件以改善界面样式,确保在不同主题下的视觉一致性。
This commit is contained in:
@@ -4,28 +4,30 @@ let rows = [], selected = null, busy = false, pending = false, dirty = false, in
|
||||
const defaults = {enabled:false,transport:'serial',format:'raw',serialPort:'',baudRate:115200,bindIp:'127.0.0.1',port:8788};
|
||||
const protocols = {'raw':'原始诊断','uid-json':'UID JSON','rid-device-json':'RID / uav','json-lines':'约定 JSON','postcard':'Postcard'};
|
||||
function state(row) {
|
||||
const s=row.status;
|
||||
if(s?.notice)return s.notice;
|
||||
if(!row.detector && row.deviceKind && !row.config.enabled)return '其他串口 · 未当作侦测机';
|
||||
if(!row.config.enabled)return '未启用';
|
||||
const s=row.status||{};
|
||||
if(!row.config?.enabled)return !row.detector&&row.deviceKind?'其他串口 · 未当作侦测机':'未启用';
|
||||
if(s.state==='disconnected')return '连接失败 · 自动重试';
|
||||
if(s.state==='connecting')return '正在连接';
|
||||
if(s.state==='connecting'||s.state==='stopped')return '正在连接';
|
||||
if(s.notice)return s.notice;
|
||||
if(!s.receivedBytes)return row.detector?'侦测串口已连接 · 还没有数据':'已连接 · 等待数据';
|
||||
if(Date.now()-(s.lastDataMs||0)>10000)return '连接中 · 暂无新数据';
|
||||
if(typeof s.lastDataMs==='number'&&Date.now()-s.lastDataMs>10000)return '连接中 · 暂无新数据';
|
||||
if(row.config.format==='raw')return '接收中 · 原始诊断';
|
||||
if(s.rejectedFrames && !s.decodedFrames)return '收到数据 · 协议不匹配';
|
||||
if(s.rejectedFrames&&!s.decodedFrames)return '收到数据 · 协议不匹配';
|
||||
if(!s.acceptedObservations)return '正在接收 · 暂无有效目标';
|
||||
return '正在接收 · 已解析目标';
|
||||
}
|
||||
const GB_NOTE='这台设备收到了报文,但帧头不符合它自己的 GB46750 要求,所以不会生成目标。';
|
||||
const UID_NOTE='坐标系待核实 · 原始坐标在目标详情中查看';
|
||||
let popFor=null;
|
||||
function linkUp(row){const state=row.status?.state;return state==='serial-open'||state==='udp-listening'||state==='tcp-listening';}
|
||||
function tone(row){
|
||||
if(!row.config?.enabled)return 'idle';
|
||||
const s=row.status||{};
|
||||
if(s.notice||s.state==='disconnected')return 'warn';
|
||||
if(s.state==='connecting'||s.state==='stopped'||!s.receivedBytes)return 'info';
|
||||
if(Date.now()-(s.lastDataMs||0)>10000)return 'info';
|
||||
if(s.state==='disconnected')return 'warn';
|
||||
if(s.state==='connecting'||s.state==='stopped')return 'info';
|
||||
if(s.notice)return 'warn';
|
||||
if(!s.receivedBytes)return 'info';
|
||||
if(typeof s.lastDataMs==='number'&&Date.now()-s.lastDataMs>10000)return 'info';
|
||||
if(row.config.format==='raw')return 'ok';
|
||||
if(s.rejectedFrames&&!s.decodedFrames)return 'warn';
|
||||
if(!s.acceptedObservations)return 'info';
|
||||
@@ -34,14 +36,28 @@ function tone(row){
|
||||
function cardStatus(row){return row.config?.enabled?state(row):'未启用';}
|
||||
function roleLabel(row){if(row.config.transport!=='serial')return '网络';if(row.detector)return '侦测机';if(row.deviceKind)return '其他串口';return '接收机';}
|
||||
function identity(row){
|
||||
const name=row.name||'未命名接收机',cut=name.indexOf(' · ');
|
||||
const head=cut<0?name:name.slice(0,cut);
|
||||
let place=cut<0?'':name.slice(cut+3);
|
||||
if(!place)place=row.devicePlace||(row.config.transport==='serial'?'—':'网络 · 手动添加');
|
||||
return {head,place};
|
||||
const name=row.name||'未命名接收机',socket=row.devicePlace||'';
|
||||
if(socket&&(name===socket||name.endsWith(` · ${socket}`))){
|
||||
const head=name===socket?name:name.slice(0,name.length-socket.length-3);
|
||||
return {head:head||name,place:socket};
|
||||
}
|
||||
if(row.deviceKind&&(name===row.deviceKind||name.startsWith(`${row.deviceKind} · `))){
|
||||
const rest=name===row.deviceKind?'':name.slice(row.deviceKind.length+3);
|
||||
return {head:row.deviceKind,place:socket||rest||'—'};
|
||||
}
|
||||
if(socket)return {head:name,place:socket};
|
||||
if(row.config.transport!=='serial')return {head:name,place:'网络 · 手动添加'};
|
||||
const cut=name.indexOf(' · ');
|
||||
return cut<0?{head:name,place:'—'}:{head:name.slice(0,cut),place:name.slice(cut+3)};
|
||||
}
|
||||
function endpoint(row){const c=row.config;return c.transport==='serial'?`${c.serialPort||'尚未选择串口'} · ${c.baudRate}`:`${c.transport==='udp'?'UDP':'TCP'} · ${c.bindIp}:${c.port}`;}
|
||||
function faults(row){const list=[];if(row.status?.lastError)list.push(row.status.lastError);if(row.status?.notice)list.push(GB_NOTE);if(row.config.format==='uid-json')list.push(UID_NOTE);return list;}
|
||||
function faults(row){
|
||||
const list=[],s=row.status||{},enabled=!!row.config?.enabled;
|
||||
if(enabled&&s.lastError&&!linkUp(row))list.push(s.lastError);
|
||||
if(enabled&&s.notice)list.push(linkUp(row)?GB_NOTE:`${s.notice}。${GB_NOTE}`);
|
||||
if(row.config?.format==='uid-json')list.push(UID_NOTE);
|
||||
return list;
|
||||
}
|
||||
function closePop(){popFor=null;const pop=$('rx-pop');if(pop)pop.hidden=true;}
|
||||
function placePop(anchor){
|
||||
const pop=$('rx-pop');if(!pop||pop.hidden||!anchor)return;
|
||||
@@ -95,7 +111,7 @@ async function refresh(){if(pending||!$('rx-cards'))return;pending=true;try{cons
|
||||
async function mutate(action){if(busy)return;busy=true;render();try{await action();await refresh();}catch(e){$('rx-error').hidden=false;$('rx-error').textContent=e.message;if($('rx-drawer').open)$('rx-message').textContent=e.message;}finally{busy=false;render();}}
|
||||
function fields(){const f=$('rx-form');$('rx-serial-fields').hidden=f.elements.transport.value!=='serial';$('rx-network-fields').hidden=f.elements.transport.value==='serial';$('rx-protocol-note').textContent=f.elements.format.value==='uid-json'?'UID 报文中的坐标系代码尚未核实:显示原始坐标,不在地图落点、不参与围栏。':f.elements.format.value==='raw'?'原始诊断只接收字节,不生成无人机目标。':'协议必须与设备实际输出一致;未知报文不会猜测为位置。';}
|
||||
function tab(diagnostic){$('rx-form').hidden=diagnostic;$('rx-diagnostic').hidden=!diagnostic;$('rx-config-tab').setAttribute('aria-pressed',String(!diagnostic));$('rx-diagnostic-tab').setAttribute('aria-pressed',String(diagnostic));diagnostics();}
|
||||
function diagnostics(){const row=rows.find(r=>r.id===selected);$('rx-status-label').textContent=row?state(row):'保存接收机后可查看诊断';const s=row?.status;const stats=s?[['设备种类',row.deviceKind||'—'],['插口位置',row.devicePlace||'—'],['设备 ID',row.hardwareId||row.id],['接收字节',s.receivedBytes],['解码帧',s.decodedFrames],['接受更新',s.acceptedObservations],['拒绝帧',s.rejectedFrames],['忽略日志',s.ignoredLines],['无效目标',s.invalidTargets],['最近接收',s.lastDataMs?new Date(s.lastDataMs).toLocaleTimeString():'—'],['连接错误',s.lastError||'无']]:[];$('rx-stats').replaceChildren(...stats.flatMap(([k,v])=>[el('dt',k),el('dd',String(v))]));$('rx-capture').disabled=!row;}
|
||||
function diagnostics(){const row=rows.find(r=>r.id===selected);$('rx-status-label').textContent=row?state(row):'保存接收机后可查看诊断';const s=row?.status;const stats=s?[['设备种类',row.deviceKind||'—'],['插口位置',row.devicePlace||'—'],['设备 ID',row.hardwareId||row.id],['接收字节',s.receivedBytes],['解码帧',s.decodedFrames],['接受更新',s.acceptedObservations],['拒绝帧',s.rejectedFrames],['忽略日志',s.ignoredLines],['无效目标',s.invalidTargets],['最近接收',s.lastDataMs?new Date(s.lastDataMs).toLocaleTimeString():'—'],['连接错误',s.lastError||'无'],...(s.notice?[['帧头提示',s.notice]]:[])]:[];$('rx-stats').replaceChildren(...stats.flatMap(([k,v])=>[el('dt',k),el('dd',String(v))]));$('rx-capture').disabled=!row;}
|
||||
function open(row){closePop();selected=row?.id||null;dirty=false;$('rx-title').textContent=row?.name||'添加接收机';$('rx-message').textContent='';$('rx-raw').textContent='尚未读取。最多显示最近 4 KiB。';const f=$('rx-form'),config=row?.config||defaults;f.elements.name.value=row?.name||'';for(const [key,value] of Object.entries(config)){if(key==='enabled')f.elements[key].checked=value;else f.elements[key].value=value;}$('rx-delete').hidden=!selected||selected==='default';fields();tab(false);$('rx-drawer').showModal();f.elements.name.focus();api('/api/receiver/ports').then(v=>$('rx-port-options').replaceChildren(...v.ports.map(p=>{const o=el('option');o.value=p;return o;}))).catch(()=>{});}
|
||||
function close(){if(dirty&&!confirm('尚有未保存的配置,放弃修改并关闭?'))return;$('rx-drawer').close();selected=null;dirty=false;}
|
||||
function init(){if(initialized||!$('rx-cards'))return;initialized=true;$('rx-add').onclick=()=>open(null);$('rx-refresh').onclick=refresh;$('rx-search').oninput=render;$('rx-close').onclick=close;$('rx-drawer').addEventListener('cancel',e=>{e.preventDefault();close();});$('rx-form').oninput=()=>{dirty=true;fields();};$('rx-form').onchange=()=>{dirty=true;fields();};$('rx-config-tab').onclick=()=>tab(false);$('rx-diagnostic-tab').onclick=()=>tab(true);
|
||||
|
||||
Reference in New Issue
Block a user