精修 WebUI 第七轮:底部状态栏 + 实时反馈
- 底部 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
This commit is contained in:
1 parent
07700c24d9
commit
857b33f413
3 files changed
+196
-23
No files matched your search
+96
-21
@@ -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");
|
||||
|
||||
+13
-2
@@ -15,7 +15,7 @@
|
||||
} catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v9" />
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v10" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
@@ -1231,8 +1231,19 @@
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
<footer class="appFooter">
|
||||
<div class="appFooterLeft">
|
||||
<span class="appConnDot" id="appConnDot" data-state="idle" aria-hidden="true"></span>
|
||||
<span class="appConnText" id="appConnText">就绪</span>
|
||||
</div>
|
||||
<div class="appFooterRight">
|
||||
<span class="appFooterMeta" id="appFooterVersion">v—</span>
|
||||
<span class="appFooterDivider" aria-hidden="true">·</span>
|
||||
<span class="appFooterMeta" id="appFooterBuild">—</span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="app.js?v=console-20260520-theme-v9"></script>
|
||||
<script src="app.js?v=console-20260520-theme-v10"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user