From 857b33f4137c515344d009cd46411d66948c2644 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 00:37:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E4=BF=AE=20WebUI=20=E7=AC=AC=E4=B8=83?= =?UTF-8?q?=E8=BD=AE=EF=BC=9A=E5=BA=95=E9=83=A8=E7=8A=B6=E6=80=81=E6=A0=8F?= =?UTF-8?q?=20+=20=E5=AE=9E=E6=97=B6=E5=8F=8D=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 底部 appFooter:左侧连接状态点(idle/ok/error 3 态 + tooltip)+ 文字;右侧版本号 + 构建标识;移动端纵向排列 - API 连接状态实时指示:apiGet/apiPost 拦截成功失败,连续 2 次失败才标 error,避免抖动 - 版本号:尝试拉 /api/version;失败时回退到 cache-bust tag - stat 数字变化时短暂闪 primary 色(statFlash 700ms),通过 setTextIfExists 自动触发 - number input 隐藏原生上下箭头 + tabular-nums 数字 - cache-bust v9 → v10 --- webui/app.js | 117 ++++++++++++++++++++++++++++++++++++++--------- webui/index.html | 15 +++++- webui/styles.css | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 23 deletions(-) diff --git a/webui/app.js b/webui/app.js index 966d8ae..7c54853 100644 --- a/webui/app.js +++ b/webui/app.js @@ -428,6 +428,25 @@ function initConfigSearch() { }); } +function initFooter() { + // 版本号尝试从 /api/version 拿;拿不到就用 cache-bust 标识做 fallback + const verEl = document.getElementById("appFooterVersion"); + const buildEl = document.getElementById("appFooterBuild"); + (async () => { + try { + const data = await apiGet("/api/version"); + if (verEl && data?.version) verEl.textContent = "v" + data.version; + if (buildEl && data?.build) buildEl.textContent = data.build; + } catch (_) { + // fallback:从当前 script 的 cache-bust 提取 + const tag = (document.currentScript?.src || document.querySelector('script[src*="app.js"]')?.src || "") + .split("v=")[1] || ""; + if (verEl) verEl.textContent = tag ? tag.split("-").pop() : "—"; + if (buildEl) buildEl.textContent = "本地"; + } + })(); +} + function initTabs() { const tabButtons = Array.from(document.querySelectorAll(".tabBtn[data-target]")); const panels = Array.from(document.querySelectorAll(".panel[data-panel]")); @@ -698,7 +717,16 @@ function startShotPolling() { function setTextIfExists(id, text) { const el = $(id); if (!el) return; - el.textContent = String(text ?? "-"); + const next = String(text ?? "-"); + // 仅对 statValue 有效:值变化时短暂高亮 + if (el.classList.contains("statValue") && el.textContent !== next && next !== "-") { + el.classList.remove("isFlash"); + // 强制重排让动画重新触发 + void el.offsetWidth; + el.classList.add("isFlash"); + setTimeout(() => el.classList.remove("isFlash"), 700); + } + el.textContent = next; } function setButtonBusy(id, busy) { @@ -985,10 +1013,49 @@ function renderTimeline(containerId, timeline) { root.appendChild(legend); } +// API 连接状态:连续失败 N 次才算 error,避免轻微抖动闪烁 +let _apiFailStreak = 0; +const _apiFailThreshold = 2; +function setConnState(state) { + const dot = document.getElementById("appConnDot"); + const txt = document.getElementById("appConnText"); + if (!dot || !txt) return; + if (state === "ok") { + dot.dataset.state = "ok"; + txt.textContent = "已连接"; + dot.title = "API 通信正常"; + } else if (state === "error") { + dot.dataset.state = "error"; + txt.textContent = "连接异常"; + dot.title = "API 请求连续失败,检查后端是否运行"; + } else { + dot.dataset.state = "idle"; + txt.textContent = "就绪"; + dot.title = "等待首个 API 请求"; + } +} +function notifyApiOk() { + _apiFailStreak = 0; + setConnState("ok"); +} +function notifyApiFail() { + _apiFailStreak++; + if (_apiFailStreak >= _apiFailThreshold) setConnState("error"); +} + async function apiGet(path) { - const res = await fetch(path, { cache: "no-store" }); - if (!res.ok) throw new Error(await res.text()); - return await res.json(); + try { + const res = await fetch(path, { cache: "no-store" }); + if (!res.ok) { + notifyApiFail(); + throw new Error(await res.text()); + } + notifyApiOk(); + return await res.json(); + } catch (e) { + notifyApiFail(); + throw e; + } } // CSRF token 缓存 @@ -1008,24 +1075,31 @@ async function getCsrfToken() { } async function apiPost(path, body) { - const token = await getCsrfToken(); - const res = await fetch(path, { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-CSRF-Token": token, - }, - body: JSON.stringify(body || {}), - }); - const data = await res.json(); - if (!res.ok) { - const errorMsg = data.error || data.message || res.statusText; - const error = new Error(errorMsg); - error.status = res.status; - error.data = data; - throw error; + try { + const token = await getCsrfToken(); + const res = await fetch(path, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-CSRF-Token": token, + }, + body: JSON.stringify(body || {}), + }); + const data = await res.json(); + if (!res.ok) { + notifyApiFail(); + const errorMsg = data.error || data.message || res.statusText; + const error = new Error(errorMsg); + error.status = res.status; + error.data = data; + throw error; + } + notifyApiOk(); + return data; + } catch (e) { + notifyApiFail(); + throw e; } - return data; } async function refreshDevices() { @@ -1796,6 +1870,7 @@ window.addEventListener("DOMContentLoaded", async () => { initTheme(); initTabs(); initConfigSearch(); + initFooter(); // 首屏统计数字加骨架,待第一次 pollStats 成功后移除 document.querySelectorAll(".stat .statValue").forEach((el) => { if ((el.textContent || "").trim() === "-") el.classList.add("skeleton"); diff --git a/webui/index.html b/webui/index.html index d6ecc10..89a1a65 100644 --- a/webui/index.html +++ b/webui/index.html @@ -15,7 +15,7 @@ } catch (e) {} })(); - +
@@ -1231,8 +1231,19 @@ +
+
+ + 就绪 +
+
+ v— + + — +
+
- + diff --git a/webui/styles.css b/webui/styles.css index 1f5372b..c12fb93 100644 --- a/webui/styles.css +++ b/webui/styles.css @@ -1249,6 +1249,20 @@ select.input { padding-right: 28px; } +/* Number inputs: hide native spinner everywhere, keep arrow keys */ +input[type="number"] { + -moz-appearance: textfield; + appearance: textfield; + font-variant-numeric: tabular-nums; +} + +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + -webkit-appearance: none; + appearance: none; + margin: 0; +} + .textarea { min-height: 96px; padding: 9px 10px; @@ -1379,6 +1393,22 @@ select.input { letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; + transition: color var(--motion-fast); +} + +.statValue.isFlash { + animation: statFlash 700ms ease-out; +} + +@keyframes statFlash { + 0% { color: var(--primary); } + 100% { color: var(--text-strong); } +} + +@media (prefers-reduced-motion: reduce) { + .statValue.isFlash { + animation: none; + } } .statTrace { @@ -2043,6 +2073,63 @@ details[open] > summary.sectionTitle::before { background-clip: padding-box; } +/* ==================== App footer ==================== */ +.appFooter { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-top: 18px; + padding: 10px 14px; + border-top: 1px solid var(--border); + color: var(--muted); + font-size: var(--text-xs); + letter-spacing: var(--tracking-wide); + text-transform: uppercase; +} + +.appFooterLeft, +.appFooterRight { + display: inline-flex; + align-items: center; + gap: 8px; +} + +.appConnDot { + width: 6px; + height: 6px; + border-radius: 50%; + background: var(--muted-soft); + box-shadow: 0 0 0 3px color-mix(in oklab, var(--muted-soft) 16%, transparent); +} + +.appConnDot[data-state="ok"] { + background: var(--success); + box-shadow: 0 0 0 3px color-mix(in oklab, var(--success) 16%, transparent); +} + +.appConnDot[data-state="error"] { + background: var(--danger); + box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 16%, transparent); + animation: statusPulse 2s ease-in-out infinite; +} + +.appConnText, +.appFooterMeta { + font-variant-numeric: tabular-nums; +} + +.appFooterDivider { + color: var(--muted-soft); +} + +@media (max-width: 640px) { + .appFooter { + flex-direction: column; + align-items: flex-start; + } +} + /* ==================== Toast ==================== */ .toastContainer { position: fixed;