精修 WebUI 第十三轮:动效、语义着色与帮助系统

- panel 切换动画:active 加 fadeIn (220ms) 替换无差别 surfaceIn,tab 切换更有反馈
- statValue 加 stateOk/stateMuted/stateError 语义着色:运行中显示 success 色(hero metric),未运行用 muted
- 预约卡倒计时实时刷新:startReservationsCountdownTick 每秒 tick,更新 .reservationRemain 文字 + isImminent/isDue 类,无需等 stats 轮询
- ? 快捷键弹出帮助 overlay:列出 ⌘K/⌘S/⌘Enter/Esc/?;ESC 或点击遮罩关闭;带毛玻璃 + scale 进出动画;输入框聚焦时不拦截
- cache-bust v15 → v16
This commit is contained in:
Codex committed 2026-05-21 09:29:38 +08:00
1 parent 3295cb3d6f
commit a40ddc3083
3 files changed
+252 -4

No files matched your search

+88 -1
View File
@@ -541,6 +541,84 @@ function initShotFullscreen() {
});
}
function initShortcutsHelp() {
const isMac = /Mac|iPhone|iPad|iPod/i.test(navigator.platform || navigator.userAgent || "");
const mod = isMac ? "⌘" : "Ctrl";
let overlay = null;
const ITEMS = [
{ keys: [mod, "K"], desc: "聚焦配置搜索" },
{ keys: [mod, "S"], desc: "保存配置" },
{ keys: [mod, "Enter"], desc: "开始运行" },
{ keys: ["Esc"], desc: "清空搜索 / 关闭弹层" },
{ keys: ["?"], desc: "显示此帮助" },
];
const open = () => {
if (overlay) return;
overlay = document.createElement("div");
overlay.className = "shortcutsOverlay";
overlay.innerHTML = `
<div class="shortcutsCard" role="dialog" aria-label="快捷键帮助">
<div class="shortcutsHeader">
<span class="shortcutsTitle">键盘快捷键</span>
<button class="shortcutsClose" type="button" aria-label="关闭">
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
</div>
<div class="shortcutsList">
${ITEMS.map(i => `<div class="shortcutsRow"><span class="shortcutsDesc">${i.desc}</span><span class="shortcutsKeys">${i.keys.map(k => `<kbd>${k}</kbd>`).join("<span class=\"shortcutsPlus\">+</span>")}</span></div>`).join("")}
</div>
</div>
`;
document.body.appendChild(overlay);
requestAnimationFrame(() => overlay.classList.add("isVisible"));
overlay.addEventListener("click", (e) => {
if (e.target === overlay || e.target.closest(".shortcutsClose")) close();
});
};
const close = () => {
if (!overlay) return;
overlay.classList.remove("isVisible");
const ref = overlay;
setTimeout(() => { try { ref.remove(); } catch (_) {} }, 160);
overlay = null;
};
document.addEventListener("keydown", (e) => {
// 输入框聚焦时不拦截 ? 字符
const inField = /^(INPUT|TEXTAREA|SELECT)$/i.test(document.activeElement?.tagName || "");
if (e.key === "?" && !inField && !e.metaKey && !e.ctrlKey) {
e.preventDefault();
overlay ? close() : open();
return;
}
if (e.key === "Escape" && overlay) {
e.preventDefault();
close();
}
});
}
function startReservationsCountdownTick() {
// 每秒 tick 更新预约卡倒计时与高亮类,无需等待 stats 轮询
setInterval(() => {
const items = document.querySelectorAll(".reservationItem[data-future-ts]");
if (!items.length) return;
const now = Date.now() / 1000;
items.forEach((card) => {
const fut = Number(card.dataset.futureTs) || 0;
if (!fut) return;
const remain = Math.max(0, Math.floor(fut - now));
const remainEl = card.querySelector(".reservationRemain");
if (remainEl) {
remainEl.textContent = remain > 0
? `${Math.floor(remain / 60)}分${remain % 60}秒后`
: "已到开奖时间";
}
card.classList.toggle("isImminent", remain > 0 && remain <= 60);
card.classList.toggle("isDue", remain === 0);
});
}, 1000);
}
function initTabs() {
const tabButtons = Array.from(document.querySelectorAll(".tabBtn[data-target]"));
const panels = Array.from(document.querySelectorAll(".panel[data-panel]"));
@@ -1748,6 +1826,8 @@ async function pollReservations() {
// 60s 内开奖:高亮提醒
if (remain > 0 && remain <= 60) card.classList.add("isImminent");
else if (remain === 0) card.classList.add("isDue");
// 把 future_ts 存到卡片,供倒计时 tick 实时刷新
if (future_ts) card.dataset.futureTs = String(future_ts);
card.innerHTML = `
<div class="reservationHeader">
@@ -1757,7 +1837,7 @@ async function pollReservations() {
<div class="reservationBody">
<div><strong>内容:</strong>${escapeHtml(item.content || '-')}</div>
<div><strong>开奖时间:</strong>${item.future_str || '-'}</div>
<div><strong>剩余时间:</strong>${remainStr}</div>
<div><strong>剩余时间:</strong><span class="reservationRemain">${remainStr}</span></div>
<div><strong>发现位置:</strong>${item.pos_seen || 0}</div>
<div><strong>直播间(清洗后):</strong>${escapeHtml(item.room_title || '-')}</div>
<div><strong>直播间原文:</strong>${escapeHtml(item.room_title_raw || '-')}</div>
@@ -1898,6 +1978,11 @@ async function pollStats() {
document.querySelectorAll(".stat .statValue.skeleton, .stat .statHint.skeleton").forEach((el) => el.classList.remove("skeleton"));
const running = s.running ? "运行中" : "未运行";
setTextIfExists("statRunning", running);
const runningEl = document.getElementById("statRunning");
if (runningEl) {
runningEl.classList.toggle("stateOk", !!s.running);
runningEl.classList.toggle("stateMuted", !s.running);
}
setTextIfExists("statPid", s.pid ?? "-");
setTextIfExists("statUptime", fmtDuration(s.uptime_seconds));
setTextIfExists("statLogLen", s.log_len ?? "-");
@@ -2043,6 +2128,8 @@ window.addEventListener("DOMContentLoaded", async () => {
initShotFullscreen();
initHeaderScroll();
initKeyboardShortcuts();
initShortcutsHelp();
startReservationsCountdownTick();
// 首屏统计数字加骨架,待第一次 pollStats 成功后移除
document.querySelectorAll(".stat .statValue").forEach((el) => {
if ((el.textContent || "").trim() === "-") el.classList.add("skeleton");
+2 -2
View File
@@ -15,7 +15,7 @@
} catch (e) {}
})();
</script>
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v15" />
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v16" />
</head>
<body>
<div class="app">
@@ -1252,6 +1252,6 @@
</footer>
</div>
<script src="app.js?v=console-20260520-theme-v15"></script>
<script src="app.js?v=console-20260520-theme-v16"></script>
</body>
</html>
+162 -1
View File
@@ -1132,7 +1132,21 @@ svg {
border-radius: var(--radius);
background: var(--surface);
box-shadow: var(--shadow-soft);
animation: surfaceIn var(--motion-slow) both;
}
.panel.active {
animation: panelFadeIn 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes panelFadeIn {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
.panel.active {
animation: none;
}
}
.panel.cardLog {
@@ -1489,6 +1503,18 @@ input[type="number"]::-webkit-outer-spin-button {
transition: color var(--motion-fast);
}
.statValue.stateOk {
color: var(--success);
}
.statValue.stateMuted {
color: var(--muted);
}
.statValue.stateError {
color: var(--danger);
}
.statValue.hasCopy {
position: relative;
padding-right: 28px;
@@ -2371,6 +2397,141 @@ details[open] > summary.sectionTitle::before {
background-clip: padding-box;
}
/* ==================== Shortcuts help overlay ==================== */
.shortcutsOverlay {
position: fixed;
inset: 0;
z-index: 90;
display: flex;
align-items: center;
justify-content: center;
padding: 24px;
background: color-mix(in oklab, var(--bg) 70%, transparent);
backdrop-filter: blur(6px);
opacity: 0;
transition: opacity 160ms ease;
}
.shortcutsOverlay.isVisible {
opacity: 1;
}
.shortcutsCard {
width: min(420px, 100%);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
background: var(--surface);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.1);
overflow: hidden;
transform: translateY(8px) scale(0.98);
transition: transform 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
:root[data-theme="dark"] .shortcutsCard {
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.5);
}
.shortcutsOverlay.isVisible .shortcutsCard {
transform: translateY(0) scale(1);
}
.shortcutsHeader {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 14px 10px;
border-bottom: 1px solid var(--border);
background: var(--surface-soft);
}
.shortcutsTitle {
font-size: 13px;
font-weight: 600;
color: var(--text-strong);
letter-spacing: var(--tracking-tight);
}
.shortcutsClose {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
padding: 0;
border: 0;
border-radius: var(--radius-sm);
color: var(--muted);
background: transparent;
cursor: pointer;
transition: color var(--motion-fast), background var(--motion-fast);
}
.shortcutsClose:hover {
color: var(--text);
background: var(--surface-muted);
}
.shortcutsList {
display: grid;
gap: 2px;
padding: 8px;
}
.shortcutsRow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 8px 10px;
border-radius: var(--radius-sm);
font-size: var(--text-sm);
color: var(--text);
}
.shortcutsRow:hover {
background: var(--surface-soft);
}
.shortcutsDesc {
color: var(--text);
}
.shortcutsKeys {
display: inline-flex;
align-items: center;
gap: 4px;
}
.shortcutsKeys kbd {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 22px;
height: 22px;
padding: 0 6px;
border: 1px solid var(--border-strong);
border-bottom-width: 2px;
border-radius: 5px;
background: var(--surface);
color: var(--text-strong);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
font-size: 11px;
letter-spacing: 0.04em;
}
.shortcutsPlus {
color: var(--muted-soft);
font-size: 10px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-reduced-motion: reduce) {
.shortcutsOverlay,
.shortcutsCard {
transition: none;
}
}
/* ==================== App footer ==================== */
.appFooter {
display: flex;