feat: 设备池默认只看在线——离线旧条目(IP 已变的幽灵设备)默认隐藏,在线优先排序;「只看在线」开关可切换查看全部(含离线/停用)

This commit is contained in:
2026-09-01 08:54:06 +08:00
parent b9fab1999d
commit ac7997176d
2 changed files with 12 additions and 2 deletions
+9 -2
View File
@@ -393,9 +393,16 @@ async function loadDevPool(){
tb.innerHTML='<tr><td colspan="7" class="empty">加载中...</td></tr>';
const r=await apiGet('/api/devices/pool');
if(!r||!r.ok){tb.innerHTML='<tr><td colspan="7" class="empty">加载失败</td></tr>';return;}
const rows=r.devices||[];
let rows=r.devices||[];
// 在线优先排序;「只看在线」勾选时过滤掉离线(IP 换了/长期离线的旧条目不再碍眼)
const onlyOnline=document.getElementById('devpool-filter-online')
? document.getElementById('devpool-filter-online').checked : false;
rows.sort((a,b)=>(b.online?1:0)-(a.online?1:0));
if(onlyOnline)rows=rows.filter(x=>x.online);
const onlineCnt=rows.filter(x=>x.online).length;
status.textContent='共 '+rows.length+' 台,在线 '+onlineCnt+' 台';
status.textContent=onlyOnline
? '在线 '+rows.length+' 台(共 '+(r.devices||[]).length+' 台配置)'
: '共 '+rows.length+' 台,在线 '+onlineCnt+' 台';
tb.innerHTML=rows.map(d=>{
const st= d.enabled
? '<span class="label label-success">启用</span>'