From 87d0ec83527cc0577d1730cd4b9bdfe228cd1209 Mon Sep 17 00:00:00 2001 From: JiuContinent Date: Sat, 31 Oct 2026 21:43:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(web-ui):=20=E5=A2=9E=E5=BC=BA=E5=9B=B4?= =?UTF-8?q?=E6=A0=8F=E5=9C=B0=E5=9B=BE=E4=BA=A4=E4=BA=92=E4=B8=8E=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E6=9C=BA=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 geofence-map-adapter.js 中添加了处理围栏顶点和圆心的拖动功能,提升用户交互体验。 - 实现了计算两点间距离的函数,以支持动态调整围栏半径。 - 更新了 receivers.js 中的状态显示逻辑,优化了设备状态的反馈信息,确保更准确的连接状态提示。 - 修改了 CSS 文件以改善界面样式,确保在不同主题下的视觉一致性。 --- crates/web-ui/public/geofence-map-adapter.js | 9 ++-- crates/web-ui/public/geofences.css | 2 +- crates/web-ui/public/receivers.js | 50 +++++++++++++------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/crates/web-ui/public/geofence-map-adapter.js b/crates/web-ui/public/geofence-map-adapter.js index 2abe3e5..da77bb6 100644 --- a/crates/web-ui/public/geofence-map-adapter.js +++ b/crates/web-ui/public/geofence-map-adapter.js @@ -11,9 +11,12 @@ function ring(g){if(g.type==='polygon')return [...g.vertices,g.vertices[0]]; for(let i=0;i<=96;i++){const bearing=i/96*2*Math.PI,p=Math.asin(Math.sin(a)*Math.cos(delta)+Math.cos(a)*Math.sin(delta)*Math.cos(bearing));const q=b+Math.atan2(Math.sin(bearing)*Math.sin(delta)*Math.cos(a),Math.cos(delta)-Math.sin(a)*Math.sin(p));points.push([q*180/Math.PI,p*180/Math.PI]);}return points; } function feature(f,draft=false){return {type:'Feature',properties:{id:f.id,enabled:f.enabled,draft},geometry:{type:'Polygon',coordinates:[ring(f.geometry)]}};} +function metres(a,b){const dLat=(b[1]-a[1])*Math.PI/180,dLon=(b[0]-a[0])*Math.PI/180,la=a[1]*Math.PI/180,lb=b[1]*Math.PI/180,h=Math.sin(dLat/2)**2+Math.cos(la)*Math.cos(lb)*Math.sin(dLon/2)**2;return 6371008.8*2*Math.asin(Math.min(1,Math.sqrt(h)));} +function handle(point,label,apply){const element=document.createElement('div');element.className='gf-handle';element.setAttribute('aria-label',label);const marker=new ml.Marker({element,anchor:'center',offset:[0,0],draggable:true}).setLngLat(point).addTo(map);marker.on('dragend',()=>{const p=marker.getLngLat();apply([p.lng,p.lat]);});markers.push(marker);} function handles(){for(const m of markers)m.remove();markers=[];if(!map||mode||!data.draft)return; - const g=data.draft.geometry,points=g.type==='circle'?[g.center]:g.vertices; - points.forEach((point,index)=>{const element=document.createElement('div');element.className='gf-handle';element.setAttribute('aria-label',g.type==='circle'?'拖动围栏圆心':`拖动围栏顶点 ${index+1}`);const marker=new ml.Marker({element,draggable:true}).setLngLat(point).addTo(map);marker.on('dragend',()=>{const p=marker.getLngLat(),geometry=structuredClone(g);marker.setLngLat(point);if(g.type==='circle')geometry.center=[p.lng,p.lat];else geometry.vertices[index]=[p.lng,p.lat];emit('rid-fence-geometry',geometry);});markers.push(marker);}); + const g=data.draft.geometry; + if(g.type==='circle'){handle(g.center,'拖动围栏圆心',p=>{const geometry=structuredClone(g);geometry.center=p;emit('rid-fence-geometry',geometry);});handle(ring(g)[24],'拖动圆边调整半径',p=>{const geometry=structuredClone(g);geometry.radius_m=Math.min(1000000,Math.max(1,metres(g.center,p)));emit('rid-fence-geometry',geometry);});return;} + g.vertices.forEach((point,index)=>handle(point,`拖动围栏顶点 ${index+1}`,p=>{const geometry=structuredClone(g);geometry.vertices[index]=p;emit('rid-fence-geometry',geometry);})); } export function render(value){data=value||data;if(!map?.getSource('fences'))return; const features=data.entries.filter(f=>f.id!==data.draft?.id).map(f=>feature(f));if(data.draft)features.push(feature(data.draft,true)); @@ -21,7 +24,7 @@ export function render(value){data=value||data;if(!map?.getSource('fences'))retu } export function targets(items){latestTargets=(items||[]).filter(t=>Number.isFinite(t.longitude)&&Number.isFinite(t.latitude));map?.getSource('targets')?.setData({type:'FeatureCollection',features:latestTargets.map(t=>({type:'Feature',properties:t,geometry:{type:'Point',coordinates:[t.longitude,t.latitude]}}))});} export function open(p){if(map){map.resize();return;}kind=p.basemap==='road'?'road':'imagery'; - try{map=new ml.Map({container:'geofence-map',center:[p.longitude,p.latitude],zoom:p.zoom??15,pitch:0,bearing:0,maxZoom:18,maxTileCacheSize:1024,style:{version:8,sources:{base:{type:'raster',tiles:[url(0)],tileSize:256,maxzoom:18},labels:{type:'raster',tiles:[url(1)],tileSize:256,maxzoom:18},targets:{type:'geojson',data:{type:'FeatureCollection',features:[]}},fences:{type:'geojson',data:{type:'FeatureCollection',features:[]}}},layers:[{id:'background',type:'background',paint:{'background-color':'#020b18'}},{id:'base',type:'raster',source:'base'},{id:'labels',type:'raster',source:'labels'},{id:'fence-fill',type:'fill',source:'fences',paint:{'fill-color':['case',['get','enabled'],'#5ba6ed','#8192a5'],'fill-opacity':['case',['get','draft'],.22,.10]}},{id:'fence-line',type:'line',source:'fences',paint:{'line-color':['case',['get','draft'],'#c5e3ff',['get','enabled'],'#7ec6ff','#8192a5'],'line-width':['case',['get','draft'],2.5,1.5]}},{id:'target-dots',type:'circle',source:'targets',paint:{'circle-radius':6,'circle-color':['match',['get','list_kind'],'white','#83dcb9','black','#ff938b','#91c9ff'],'circle-stroke-color':'#020b18','circle-stroke-width':2}}]}}); + try{map=new ml.Map({container:'geofence-map',center:[p.longitude,p.latitude],zoom:p.zoom??15,pitch:0,bearing:0,maxZoom:18,maxTileCacheSize:1024,boxZoom:false,dragRotate:false,style:{version:8,sources:{base:{type:'raster',tiles:[url(0)],tileSize:256,maxzoom:18},labels:{type:'raster',tiles:[url(1)],tileSize:256,maxzoom:18},targets:{type:'geojson',data:{type:'FeatureCollection',features:[]}},fences:{type:'geojson',data:{type:'FeatureCollection',features:[]}}},layers:[{id:'background',type:'background',paint:{'background-color':'#020b18'}},{id:'base',type:'raster',source:'base'},{id:'labels',type:'raster',source:'labels'},{id:'fence-fill',type:'fill',source:'fences',paint:{'fill-color':['case',['get','enabled'],'#5ba6ed','#8192a5'],'fill-opacity':['case',['get','draft'],.22,.10]}},{id:'fence-line',type:'line',source:'fences',layout:{'line-join':'round','line-cap':'round'},paint:{'line-color':['case',['get','draft'],'#d7ecff',['get','enabled'],'#7ec6ff','#8192a5'],'line-width':['case',['get','draft'],2.5,1.5]}},{id:'target-dots',type:'circle',source:'targets',paint:{'circle-radius':6,'circle-color':['match',['get','list_kind'],'white','#83dcb9','black','#ff938b','#91c9ff'],'circle-stroke-color':'#020b18','circle-stroke-width':2}}]}}); buffer=attachTileBuffer(map,()=>kind);observer=new ResizeObserver(()=>map?.resize());observer.observe(document.getElementById('geofence-map'));map.addControl(new ml.NavigationControl({showCompass:false}),'bottom-left');map.addControl(new ml.AttributionControl({customAttribution:'天地图 © 自然资源部 · 本地监测围栏',compact:true}),'bottom-right'); map.on('load',()=>{render(data);targets(latestTargets);});map.on('error',e=>{if(!['base','labels'].includes(e.sourceId))emit('rid-fence-map-error',{message:'围栏地图操作失败,请使用坐标编辑并检查 WebGL。'});}); map.on('click',e=>{if(mode==='circle'){const radius=data.draft?.geometry?.radius_m||500;emit('rid-fence-geometry',{type:'circle',center:[e.lngLat.lng,e.lngLat.lat],radius_m:radius});tool('');} diff --git a/crates/web-ui/public/geofences.css b/crates/web-ui/public/geofences.css index 5ab3cdd..f3873cb 100644 --- a/crates/web-ui/public/geofences.css +++ b/crates/web-ui/public/geofences.css @@ -1,4 +1,4 @@ -#geofence-view{background:#020b18;backdrop-filter:none;overflow:hidden}[hidden]{display:none!important}.gf-stage{position:relative;height:100%;min-height:480px}.gf-stage #geofence-map{position:absolute;inset:0}.gf-heading{position:absolute;left:24px;top:22px;right:405px;pointer-events:none}.gf-heading{padding:14px 16px;border-radius:12px;max-width:600px;background:linear-gradient(90deg,#061221ed,#061221bb)}.gf-heading h1{font-size:23px;margin:0 0 8px}.gf-heading p{font-size:12px;color:#b5c6d9;line-height:1.7}.gf-tools{display:flex;flex-wrap:wrap;gap:7px;pointer-events:auto;margin-top:16px}.gf-tools button{background:rgba(6,18,33,.85);font-size:12px}.gf-drawer{position:absolute;right:20px;top:20px;bottom:45px;width:350px;display:flex;flex-direction:column;overflow:hidden;border:1px solid rgba(179,213,255,.32);border-radius:14px;background:rgba(6,18,33,.40);backdrop-filter:blur(7px) brightness(.55);box-shadow:0 16px 45px #0005}.gf-drawer-heading{display:flex;align-items:center;justify-content:space-between;padding:16px 18px;border-bottom:1px solid #b3d5ff32}.gf-drawer h2{font-size:17px;margin:0}.gf-scroll{padding:0 18px 18px;overflow:auto;flex:1;min-height:0;scrollbar-width:thin}.gf-section-title{display:flex;align-items:center;justify-content:space-between;margin:20px 0 12px;color:#b5c6d9;font-size:12px}.gf-section-title button{padding:5px 9px;font-size:11px}.gf-section-title h3{font-size:13px;margin:0}.gf-entry{display:flex;width:100%;align-items:center;justify-content:space-between;text-align:left;gap:12px;margin:8px 0;padding:13px;background:rgba(2,11,24,.6);font-size:13px}.gf-entry small{font-size:10px;color:#b5c6d9;white-space:nowrap}.gf-entry[aria-pressed=true]{border-color:#94caff;background:#245d9d40}.gf-entry span{overflow-wrap:anywhere}#gf-list{max-height:220px;overflow:auto}.gf-drawer label{display:block;font-size:12px;color:#b5c6d9;margin:14px 0 7px}.gf-drawer :is(input:not([type=checkbox]),select,textarea){width:100%;min-width:0;padding:10px;background:rgba(2,11,24,.72);border:1px solid #b3d5ff45;border-radius:7px;color:#e9f0fa;font:inherit;font-size:12px;box-sizing:border-box}.gf-drawer input[type=checkbox]{width:auto;margin-right:8px}.gf-drawer select option{background:#061221}.gf-drawer textarea{resize:vertical}.gf-field-row{display:grid;grid-template-columns:1fr 1fr;gap:12px}.gf-field-row input{margin-top:7px}.gf-explain,#gf-vertices-help{font-size:11px;line-height:1.8;color:#b5c6d9}.gf-editor-actions{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:8px;align-items:center;margin-top:16px;padding:12px 0 2px;position:static;background:transparent;border:0;border-top:1px solid #b3d5ff2e}.gf-editor-actions button{width:auto;height:auto;min-height:36px;font-size:12px;padding:8px 14px;box-shadow:none;white-space:nowrap}.gf-editor-actions .primary{width:100%;min-width:0;background:#245d9d}.gf-editor-actions .primary:hover:not(:disabled){transform:none}body.b .gf-drawer .gf-editor-actions{background:transparent;border-color:transparent;border-top:1px solid #b3d5ff2e;box-shadow:none;color:inherit}.gf-footer{padding:10px 18px;background:#061221d9;border-top:1px solid #b3d5ff32}.gf-footer p{margin:0;line-height:1.8;font-size:12px;color:#b5c6d9}.gf-footer p[data-error=true]{color:#ffb8b1}#gf-events{padding:0;list-style:none;margin:0}#gf-events li{padding:12px 0;border-bottom:1px solid #b3d5ff25;font-size:12px;line-height:1.8;overflow-wrap:anywhere}#gf-events time{display:block;color:#b5c6d9;font-size:10px}.gf-map-status{position:absolute;bottom:8px;left:16px;right:16px;margin:0;pointer-events:none;font-size:11px;color:#b5c6d9;background:#061221c9;padding:7px 12px;border-radius:7px;width:fit-content;max-width:calc(100% - 32px)}.gf-stage .maplibregl-ctrl-group{background:#061221d9;border:1px solid #b3d5ff52}.gf-stage .maplibregl-ctrl-icon{filter:invert(1)}.gf-stage .maplibregl-ctrl-attrib{background:#061221d9;color:#b5c6d9}.gf-stage .maplibregl-ctrl-attrib a{color:#b5c6d9}.gf-handle{width:14px;height:14px;border-radius:50%;border:2px solid #e9f0fa;background:#245d9d;cursor:grab}.gf-stage button:focus-visible,.gf-stage input:focus-visible,.gf-stage textarea:focus-visible,.gf-stage select:focus-visible{outline:2px solid #9cceff;outline-offset:3px}.gf-stage button:disabled{opacity:.45;cursor:not-allowed}@supports not (backdrop-filter:blur(7px)){.gf-drawer{background:#061221f5}}@media(max-width:1000px){.gf-drawer{width:320px;right:14px}.gf-heading{right:355px;left:18px}.gf-heading h1{font-size:20px}}@media(max-width:767px),(max-height:570px){#geofence-view{overflow:auto}.gf-stage{height:auto;min-height:100%;padding-top:390px}.gf-stage #geofence-map{height:390px;bottom:auto}.gf-heading{top:18px;left:16px;right:16px}.gf-heading h1{font-size:19px}.gf-heading>p{max-width:100%;font-size:11px}.gf-tools{gap:5px;margin-top:12px}.gf-tools button{font-size:11px;padding:7px 9px}.gf-drawer{position:relative;inset:auto;width:auto;margin:14px;max-height:none;background:rgba(6,18,33,.7)}.gf-scroll{overflow:visible}.gf-map-status{position:relative;bottom:auto;left:auto;margin:14px;width:auto;max-width:none}.gf-editor-actions{position:static;background:none}.gf-stage .maplibregl-ctrl-bottom-right{bottom:auto;top:355px}.gf-field-row{gap:10px}} +#geofence-view{background:#020b18;backdrop-filter:none;overflow:hidden}[hidden]{display:none!important}.gf-stage{position:relative;height:100%;min-height:480px}.gf-stage #geofence-map{position:absolute;inset:0}.gf-heading{position:absolute;left:24px;top:22px;right:405px;pointer-events:none}.gf-heading{padding:14px 16px;border-radius:12px;max-width:600px;background:linear-gradient(90deg,#061221ed,#061221bb)}.gf-heading h1{font-size:23px;margin:0 0 8px}.gf-heading p{font-size:12px;color:#b5c6d9;line-height:1.7}.gf-tools{display:flex;flex-wrap:wrap;gap:7px;pointer-events:auto;margin-top:16px}.gf-tools button{background:rgba(6,18,33,.85);font-size:12px}.gf-drawer{position:absolute;right:20px;top:20px;bottom:45px;width:350px;display:flex;flex-direction:column;overflow:hidden;border:1px solid rgba(179,213,255,.32);border-radius:14px;background:rgba(6,18,33,.40);backdrop-filter:blur(7px) brightness(.55);box-shadow:0 16px 45px #0005}.gf-drawer-heading{display:flex;align-items:center;justify-content:space-between;padding:16px 18px;border-bottom:1px solid #b3d5ff32}.gf-drawer h2{font-size:17px;margin:0}.gf-scroll{padding:0 18px 18px;overflow:auto;flex:1;min-height:0;scrollbar-width:thin}.gf-section-title{display:flex;align-items:center;justify-content:space-between;margin:20px 0 12px;color:#b5c6d9;font-size:12px}.gf-section-title button{padding:5px 9px;font-size:11px}.gf-section-title h3{font-size:13px;margin:0}.gf-entry{display:flex;width:100%;align-items:center;justify-content:space-between;text-align:left;gap:12px;margin:8px 0;padding:13px;background:rgba(2,11,24,.6);font-size:13px}.gf-entry small{font-size:10px;color:#b5c6d9;white-space:nowrap}.gf-entry[aria-pressed=true]{border-color:#94caff;background:#245d9d40}.gf-entry span{overflow-wrap:anywhere}#gf-list{max-height:220px;overflow:auto}.gf-drawer label{display:block;font-size:12px;color:#b5c6d9;margin:14px 0 7px}.gf-drawer :is(input:not([type=checkbox]),select,textarea){width:100%;min-width:0;padding:10px;background:rgba(2,11,24,.72);border:1px solid #b3d5ff45;border-radius:7px;color:#e9f0fa;font:inherit;font-size:12px;box-sizing:border-box}.gf-drawer input[type=checkbox]{width:auto;margin-right:8px}.gf-drawer select option{background:#061221}.gf-drawer textarea{resize:vertical}.gf-field-row{display:grid;grid-template-columns:1fr 1fr;gap:12px}.gf-field-row input{margin-top:7px}.gf-explain,#gf-vertices-help{font-size:11px;line-height:1.8;color:#b5c6d9}.gf-editor-actions{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:8px;align-items:center;margin-top:16px;padding:12px 0 2px;position:static;background:transparent;border:0;border-top:1px solid #b3d5ff2e}.gf-editor-actions button{width:auto;height:auto;min-height:36px;font-size:12px;padding:8px 14px;box-shadow:none;white-space:nowrap}.gf-editor-actions .primary{width:100%;min-width:0;background:#245d9d}.gf-editor-actions .primary:hover:not(:disabled){transform:none}body.b .gf-drawer .gf-editor-actions{background:transparent;border-color:transparent;border-top:1px solid #b3d5ff2e;box-shadow:none;color:inherit}.gf-footer{padding:10px 18px;background:#061221d9;border-top:1px solid #b3d5ff32}.gf-footer p{margin:0;line-height:1.8;font-size:12px;color:#b5c6d9}.gf-footer p[data-error=true]{color:#ffb8b1}#gf-events{padding:0;list-style:none;margin:0}#gf-events li{padding:12px 0;border-bottom:1px solid #b3d5ff25;font-size:12px;line-height:1.8;overflow-wrap:anywhere}#gf-events time{display:block;color:#b5c6d9;font-size:10px}.gf-map-status{position:absolute;bottom:8px;left:16px;right:16px;margin:0;pointer-events:none;font-size:11px;color:#b5c6d9;background:#061221c9;padding:7px 12px;border-radius:7px;width:fit-content;max-width:calc(100% - 32px)}.gf-stage .maplibregl-ctrl-group{background:#061221d9;border:1px solid #b3d5ff52}.gf-stage .maplibregl-ctrl-icon{filter:invert(1)}.gf-stage .maplibregl-ctrl-attrib{background:#061221d9;color:#b5c6d9}.gf-stage .maplibregl-ctrl-attrib a{color:#b5c6d9}.gf-handle{width:16px;height:16px;box-sizing:border-box;border-radius:50%;border:2px solid #e9f0fa;background:#245d9d;cursor:grab;touch-action:none}.gf-handle[aria-label^='拖动圆边']{background:#e9f0fa;border-color:#245d9d}.gf-stage button:focus-visible,.gf-stage input:focus-visible,.gf-stage textarea:focus-visible,.gf-stage select:focus-visible{outline:2px solid #9cceff;outline-offset:3px}.gf-stage button:disabled{opacity:.45;cursor:not-allowed}@supports not (backdrop-filter:blur(7px)){.gf-drawer{background:#061221f5}}@media(max-width:1000px){.gf-drawer{width:320px;right:14px}.gf-heading{right:355px;left:18px}.gf-heading h1{font-size:20px}}@media(max-width:767px),(max-height:570px){#geofence-view{overflow:auto}.gf-stage{height:auto;min-height:100%;padding-top:390px}.gf-stage #geofence-map{height:390px;bottom:auto}.gf-heading{top:18px;left:16px;right:16px}.gf-heading h1{font-size:19px}.gf-heading>p{max-width:100%;font-size:11px}.gf-tools{gap:5px;margin-top:12px}.gf-tools button{font-size:11px;padding:7px 9px}.gf-drawer{position:relative;inset:auto;width:auto;margin:14px;max-height:none;background:rgba(6,18,33,.7)}.gf-scroll{overflow:visible}.gf-map-status{position:relative;bottom:auto;left:auto;margin:14px;width:auto;max-width:none}.gf-editor-actions{position:static;background:none}.gf-stage .maplibregl-ctrl-bottom-right{bottom:auto;top:355px}.gf-field-row{gap:10px}} .gf-stage .maplibregl-popup-content{background:#061221;color:#e9f0fa;border:1px solid #b3d5ff52;padding:16px 28px 16px 16px;line-height:1.8;max-width:280px}.gf-stage .maplibregl-popup-close-button{color:#e9f0fa}.gf-stage .maplibregl-popup-tip{border-top-color:#061221} .gf-drawer .gf-switch{display:flex;align-items:center;gap:8px}.gf-drawer .gf-switch input{margin:0;flex:0 0 auto} diff --git a/crates/web-ui/public/receivers.js b/crates/web-ui/public/receivers.js index ecb1b15..e0b05da 100644 --- a/crates/web-ui/public/receivers.js +++ b/crates/web-ui/public/receivers.js @@ -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);