diff --git a/webui/app.js b/webui/app.js index 29e07d5..a7ea931 100644 --- a/webui/app.js +++ b/webui/app.js @@ -516,11 +516,17 @@ function initKeyboardShortcuts() { function initHeaderScroll() { const header = document.querySelector(".header"); - if (!header) return; + const scrollTop = document.getElementById("btnScrollTop"); const onScroll = () => { - header.classList.toggle("isScrolled", window.scrollY > 8); + if (header) header.classList.toggle("isScrolled", window.scrollY > 8); + if (scrollTop) scrollTop.toggleAttribute("hidden", window.scrollY < 240); }; window.addEventListener("scroll", onScroll, { passive: true }); + if (scrollTop) { + scrollTop.addEventListener("click", () => { + window.scrollTo({ top: 0, behavior: "smooth" }); + }); + } onScroll(); } @@ -599,6 +605,14 @@ function initShortcutsHelp() { }); } +function updateTabBadge(target, count) { + const btn = document.querySelector(`.tabBtn[data-target="${target}"]`); + if (!btn) return; + const n = Math.max(0, Number(count) || 0); + if (n > 0) btn.setAttribute("data-badge", n > 99 ? "99+" : String(n)); + else btn.removeAttribute("data-badge"); +} + function startReservationsCountdownTick() { // 每秒 tick 更新预约卡倒计时与高亮类,无需等待 stats 轮询 setInterval(() => { @@ -1195,11 +1209,85 @@ function renderTimeline(containerId, timeline) { svg.appendChild(p); } + // Crosshair hover layer:垂直线 + 当前 bin 的 dot 圆 + tooltip + const NS = "http://www.w3.org/2000/svg"; + const crossLine = document.createElementNS(NS, "line"); + crossLine.setAttribute("y1", String(padT)); + crossLine.setAttribute("y2", String(H - padB)); + crossLine.setAttribute("stroke", "var(--text)"); + crossLine.setAttribute("stroke-opacity", "0.25"); + crossLine.setAttribute("stroke-dasharray", "2 3"); + crossLine.setAttribute("pointer-events", "none"); + crossLine.setAttribute("visibility", "hidden"); + svg.appendChild(crossLine); + // 容器(外层 root)作为相对定位锚点 + root.style.position = "relative"; + + const tip = document.createElement("div"); + tip.className = "timelineTip"; + tip.hidden = true; + root.appendChild(tip); + + const fmtTimeOf = (i) => { + if (!startTs || !binSec) return ""; + try { return new Date((startTs + i * binSec) * 1000).toLocaleTimeString(); } catch { return ""; } + }; + const SERIES_LABEL = { + fudai_open_detail: "打开详情", + fudai_attend_ok: "参与成功", + fudai_attend_fail: "参与失败", + fudai_result_win: "中奖", + fudai_result_no_win: "未中奖", + fudai_skip: "跳过", + switch_room: "切换直播间", + }; + + const onMove = (ev) => { + const rect = svg.getBoundingClientRect(); + const xRatio = (ev.clientX - rect.left) / rect.width; + if (xRatio < 0 || xRatio > 1) return; + const xCoord = padL + (W - padL - padR) * xRatio; + // 找最近的 bin + let i = Math.round(((xCoord - padL) / Math.max(1, W - padL - padR)) * (bins - 1)); + if (i < 0) i = 0; else if (i >= bins) i = bins - 1; + const xOnAxis = xAt(i); + crossLine.setAttribute("x1", String(xOnAxis)); + crossLine.setAttribute("x2", String(xOnAxis)); + crossLine.setAttribute("visibility", "visible"); + + // 生成 tip 内容 + const lines = []; + let total = 0; + for (const k of TIMELINE_SERIES_KEYS) { + const arr = Array.isArray(series[k]) ? series[k] : []; + const v = Number(arr[i]) || 0; + total += v; + if (v > 0) lines.push(`${SERIES_LABEL[k] || k}${v}`); + } + if (total === 0) lines.push(`无事件`); + tip.innerHTML = `