From 159649b6a04007dd788824cea7018c017b41bed1 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Tue, 11 Aug 2026 10:00:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20adb=E8=BF=9C=E7=A8=8B=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E4=B8=8ETailscale=E7=AE=A1=E7=90=86=E4=BB=8E=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E9=A1=B5=E7=A7=BB=E8=87=B3=E5=B7=A5=E5=85=B7Tab?= =?UTF-8?q?=EF=BC=88=E7=BB=B4=E6=8A=A4=E4=BB=85=E4=BF=9D=E7=95=99STF?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=EF=BC=89=EF=BC=8C=E8=AE=BE=E5=A4=87=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=85=B1=E4=BA=AB=E7=BC=93=E5=AD=98+=E5=A4=8D?= =?UTF-8?q?=E7=94=A8esc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/admin/monitor.js | 45 +++++++----- templates/admin/monitor.html | 130 ++++++++++++++++------------------- 2 files changed, 88 insertions(+), 87 deletions(-) diff --git a/static/admin/monitor.js b/static/admin/monitor.js index 1bce159..0763f42 100644 --- a/static/admin/monitor.js +++ b/static/admin/monitor.js @@ -289,16 +289,15 @@ function showTab(name){ if(name==='monitor'){loadMonitor();_monitorTimer=setInterval(loadMonitor,5000);} if(name==='tasks'){showSubTab('tasks',_activeSubs.tasks);loadTasks();loadCustomActions();} if(name==='apps'){showSubTab('apps',_activeSubs.apps);loadApks();} - if(name==='maintenance'){showSubTab('maintenance',_activeSubs.maintenance);loadAdbDevices();loadTailscaleDevices();} - if(name==='tools'){showSubTab('tools',_activeSubs.tools);loadToolsDevices();} + if(name==='tools'){showSubTab('tools',_activeSubs.tools);loadToolsDevices();loadAdbDevices();loadTailscaleDevices();} if(name==='groups')loadGroups(); if(name==='logs'){loadLogs();if(document.getElementById('log-auto').checked)_logTimer=setInterval(loadLogs,3000);} if(name==='users')loadUsers(); } -// ================== 页内子分栏(任务/应用/维护/工具 通用) ================== +// ================== 页内子分栏(任务/应用/工具 通用) ================== // 每个带子分栏的 Tab 记住上次选中的子分栏,切走再切回来保持原位 -let _activeSubs = {tasks: 'plan', apps: 'apks', maintenance: 'stf', tools: 'clipboard'}; +let _activeSubs = {tasks: 'plan', apps: 'apks', tools: 'clipboard'}; function showSubTab(tabId, name){ _activeSubs[tabId] = name; @@ -311,15 +310,25 @@ function showSubTab(tabId, name){ let _clipDevices = []; // [{serial, state}],来源 /api/adb/devices(本地 adb + STF 池) let _clipSelected = new Set(); -function _escHtml(s){ - return String(s==null?'':s).replace(/[&<>"']/g, c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); +// 本地 adb 设备列表共享缓存(剪贴板/终端两个面板同源,10 秒内复用避免重复请求;force 强制刷新) +let _adbDevicesCache = null; // {ts, data} + +async function _fetchAdbDevices(force){ + const now = Date.now(); + if(!force && _adbDevicesCache && now - _adbDevicesCache.ts < 10000){ + return _adbDevicesCache.data; + } + const r = await apiGet('/api/adb/devices'); + if(!r || !r.ok) return null; + _adbDevicesCache = {ts: now, data: r.devices || []}; + return _adbDevicesCache.data; } -async function loadToolsDevices(){ - const r = await apiGet('/api/adb/devices'); +async function loadToolsDevices(force){ + const list = await _fetchAdbDevices(force); const status = document.getElementById('clip-status'); - if(!r||!r.ok){status.textContent='加载失败';showToast('加载设备失败: '+(r&&r.error||''),'error');return;} - _clipDevices = r.devices||[]; + if(list === null){status.textContent='加载失败';showToast('加载设备失败','error');return;} + _clipDevices = list; const wrap = document.getElementById('clip-devices'); if(!_clipDevices.length){ wrap.innerHTML='
无可用设备(本地 adb 或 STF 池均无)
'; @@ -329,9 +338,9 @@ async function loadToolsDevices(){ wrap.innerHTML = _clipDevices.map(d=>{ const st = d.state==='stf' ? 'STF池' : (d.state==='device' ? '已连接' : d.state); const stCls = (d.state==='device'||d.state==='stf') ? 'label-success' : 'label-warning'; - return '