From 9bd16e96a91cc839d39fb3bc3cfc1557665621ae Mon Sep 17 00:00:00 2001 From: jinghui <181050043@qq.com> Date: Mon, 26 Oct 2026 22:38:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=8F=AF=E6=9A=82=E5=81=9C=EF=BC=8C=E5=B9=B6=E5=AF=B9=E8=BE=93?= =?UTF-8?q?=E5=85=A5/=E6=8A=BD=E5=B1=89/=E8=A1=A8=E5=8D=95=E9=A1=B5?= =?UTF-8?q?=E5=81=9A=E6=97=A0=E6=84=9F=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ public/app.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++- public/index.html | 1 + public/style.css | 4 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c54dfbf..8764e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # 更新日志 +## 2026-10-26 → ✨ 自动刷新可暂停,且不再打断操作 + +- ✨ 顶栏新增「⏸ 暂停 / ▶ 继续」按钮:暂停后数据不再自动变化,状态存 `localStorage['dc.paused']`,刷新页面仍保持 +- ✨ **无感刷新**:以下情况自动跳过重绘 —— 输入框/下拉正在聚焦、容器详情抽屉打开、设置与备份页、鼠标/键盘/滚轮操作后 5 秒内 +- ✨ 静默刷新保留滚动位置(窗口与 `#view`),不再回到顶部 +- 🔧 定时器统一走 `canAutoRefresh()` 闸门;列表空闲时仍按间隔正常刷新(实测 9 秒内节点已被替换) +- 🔧 设置页此前每 3 秒被重绘导致填一半的表单、未保存的 Webhook 被冲掉 —— 现在完全不自动重绘 +- ✅ 实测:设置页填入 webhook 并聚焦输入框,11 秒后内容与焦点保持;打开容器抽屉(xteve)12 秒(4 个刷新周期)仍保持打开、内容正常;暂停按钮切换与持久化正确;空闲列表仍自动刷新 + ## 2026-10-26 → ✨ 本地镜像支持导入 - ✨ 本地镜像页批量条新增「导入镜像」:选择 `docker save` 导出的 `.tar` / `.tar.gz` / `.tgz` 即可导入,按钮实时显示「上传 42%」 diff --git a/public/app.js b/public/app.js index dfe70fa..0a3d30d 100644 --- a/public/app.js +++ b/public/app.js @@ -7,6 +7,39 @@ let serverBuild = null; const state = { view: 'apps', filter: 'all', sort: 'severity', order: 'desc', q: '', timer: null, current: null, currentApp: null, tab: 'stat', appTab: 'containers', insightOpen: false, traffic: { range: 'today', date: '' }, sel: new Set(), imgSel: new Set(), pendSel: new Set() }; const REFRESH_KEY = 'dc.refreshMs'; state.refreshMs = Math.min(30000, Math.max(1000, Number(localStorage.getItem(REFRESH_KEY)) || 3000)); +const PAUSE_KEY = 'dc.paused'; +state.paused = localStorage.getItem(PAUSE_KEY) === '1'; +state.lastAct = 0; +['pointerdown', 'keydown', 'wheel', 'touchstart'].forEach(ev => + document.addEventListener(ev, () => { state.lastAct = Date.now(); }, { capture: true, passive: true })); + +/* 自动刷新闸门:暂停 / 隐藏 / 正在填表 / 抽屉打开 / 表单页 / 刚有操作 → 都不重绘 */ +function canAutoRefresh() { + if (state.paused) return false; + if (document.hidden) return false; + const ae = document.activeElement; + if (ae && /^(INPUT|SELECT|TEXTAREA)$/.test(ae.tagName)) return false; + const dr = document.getElementById('drawer'); + if (dr && !dr.classList.contains('hidden')) return false; + if (['settings', 'backup'].includes(state.view)) return false; + if (Date.now() - state.lastAct < 5000) return false; + return true; +} + +function paintPauseBtn() { + const b = document.getElementById('pauseBtn'); + if (!b) return; + b.textContent = state.paused ? '▶ 继续' : '⏸ 暂停'; + b.classList.toggle('paused', state.paused); + b.title = state.paused ? '已暂停自动刷新,点此继续' : '暂停自动刷新(暂停后数据不再变化)'; +} + +function togglePause(force) { + state.paused = typeof force === 'boolean' ? force : !state.paused; + localStorage.setItem(PAUSE_KEY, state.paused ? '1' : '0'); + paintPauseBtn(); + toast(state.paused ? '已暂停自动刷新' : '已恢复自动刷新'); +} const ICONS = { grid: '', @@ -115,13 +148,21 @@ function go(view) { $('#addBtn').textContent = view === 'registry' ? '拉取镜像' : view === 'images' ? '清理悬空镜像' : '添加容器'; clearInterval(state.timer); if ($('#refreshSel')) $('#refreshSel').value = String(state.refreshMs); + const pb = $('#pauseBtn'); + if (pb) pb.onclick = () => togglePause(); + paintPauseBtn(); render(); state.timer = setInterval(() => { - if (!document.hidden && (state.view === view || state.view === 'app-detail')) render(true); + if (!canAutoRefresh()) return; + if (state.view === view || state.view === 'app-detail') render(true); }, state.refreshMs); + paintPauseBtn(); } async function render(silent) { + const scY = window.scrollY || 0; + const viewEl = document.getElementById('view'); + const scV = viewEl ? viewEl.scrollTop : 0; try { if (state.view === 'app-detail') { if (state.appTab === 'containers' && state.currentApp) return openApp(state.currentApp); @@ -136,6 +177,13 @@ async function render(silent) { if (state.view === 'backup') return renderBackup(); if (state.view === 'settings') return renderSettings(); } catch (e) { if (!silent) $('#view').innerHTML = `
加载失败:${esc(e.message)}
`; } + finally { + if (silent) { + window.scrollTo(0, scY); + const v2 = document.getElementById('view'); + if (v2) v2.scrollTop = scV; + } + } } /* ---------------- 主机信息 ---------------- */ diff --git a/public/index.html b/public/index.html index c596fa9..1b58199 100644 --- a/public/index.html +++ b/public/index.html @@ -61,6 +61,7 @@ + diff --git a/public/style.css b/public/style.css index 65a2a4d..f42ccdc 100644 --- a/public/style.css +++ b/public/style.css @@ -368,3 +368,7 @@ table.tb th.num{text-align:right} .pend-chk{display:flex;align-items:center;margin-right:2px} .pend-chk input{width:14px;height:14px;cursor:pointer;accent-color:#1a73e8} .pend-top{gap:6px} + +/* 暂停自动刷新按钮 */ +#pauseBtn.paused{background:#fff4e8;border-color:#f7c99a;color:#b2530a} +#pauseBtn.paused:hover{background:#ffe9d6}