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='