精修 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:
1 parent
3295cb3d6f
commit
a40ddc3083
3 files changed
+252
-4
No files matched your search
+88
-1
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user