diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb475e..90ff1e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +## 2026-10-26 → ✨ 服务端更新后页面自动刷新(解决"改了看不到") + +- ✨ `/api/host` 返回 `build`(每次进程启动生成),前端发现 build 变化自动 `location.reload()` +- 🔧 已开着的老页面会在下一次 3 秒轮询时自动切到新版本,不需要手动 Ctrl+F5 +- 🔧 菜单「运行的容器」文案加了 `#navContainersLabel` 并在刷新时兜底校正 +- ✅ 实测:页面开着 → `docker restart` 服务 → 6 秒内页面自刷、标记丢失、build 更新、菜单为新文案 + ## 2026-10-26 → 🔧 「应用」菜单改名「概览」并作为默认页 - 🔧 左侧菜单「应用」→「**概览**」,页面标题同步 diff --git a/public/app.js b/public/app.js index 3513ddf..5d13b13 100644 --- a/public/app.js +++ b/public/app.js @@ -3,6 +3,7 @@ /* ---------------- 基础 ---------------- */ const $ = (s, r = document) => r.querySelector(s); const $$ = (s, r = document) => [...r.querySelectorAll(s)]; +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 }; const REFRESH_KEY = 'dc.refreshMs'; state.refreshMs = Math.min(30000, Math.max(1000, Number(localStorage.getItem(REFRESH_KEY)) || 3000)); @@ -115,6 +116,11 @@ async function render(silent) { /* ---------------- 主机信息 ---------------- */ async function refreshHost() { const h = await api('/api/host'); + if (h.build) { + if (serverBuild && serverBuild !== h.build) { location.reload(); return h; } + serverBuild = h.build; + } + const navCl = $('#navContainersLabel'); if (navCl && navCl.textContent !== '运行的容器') navCl.textContent = '运行的容器'; $('#hostMini').innerHTML = `${esc(h.hostname)}
${h.cpus} 核 · 内存 ${fmtBytes(h.memTotal)}
运行 ${h.running} / 共 ${h.containers} 容器`; $('#navRunning').textContent = h.running; $('#navStopped').textContent = (h.stopped || 0) + (h.pending || 0); diff --git a/public/index.html b/public/index.html index 83de510..61d41bc 100644 --- a/public/index.html +++ b/public/index.html @@ -17,7 +17,7 @@