精修 WebUI 第十六轮:滚动顶按钮 / 连体按钮组 / 图表 hover / 徽章

- 滚动 floating 按钮:scrollY > 240 时右下方显示,毛玻璃圆形,平滑滚回顶部;移动端调高避让 toast
- WiFi ADB 操作改 .btnGroup 连体组合:共享圆角、中间无双边、focus z-index 抬起
- timeline 图加 hover 十字线 + tooltip:crosshair 跟随光标 snap 到最近 bin,浮层显示该 bin 的所有系列与时间,无事件显示空状态
- tabBtn[data-badge] 数字徽章:active 时反色 primary;预约数据更新时同步预约 tab 的徽章
- cache-bust v18 → v19
This commit is contained in:
Codex committed 2026-05-21 09:29:38 +08:00
1 parent 94e8d37d18
commit 51d8d53a2b
3 files changed
+248 -8

No files matched your search

+93 -3
View File
@@ -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(`<span><i class="timelineDotMark" style="background:${TIMELINE_STROKES[k]?.stroke || 'var(--primary)'};opacity:${TIMELINE_STROKES[k]?.opacity ?? 1}"></i>${SERIES_LABEL[k] || k}</span><b>${v}</b>`);
}
if (total === 0) lines.push(`<span class="hint">无事件</span>`);
tip.innerHTML = `<div class="timelineTipTime">${fmtTimeOf(i)}</div><div class="timelineTipBody">${lines.join("")}</div>`;
tip.hidden = false;
// tip 位置:根据当前 svg 实际宽度比例换算到 root 内 px
const actualX = (xOnAxis / W) * rect.width;
let leftPx = actualX + 8;
if (leftPx + 160 > rect.width) leftPx = actualX - 168;
if (leftPx < 0) leftPx = 4;
tip.style.left = `${Math.max(0, leftPx)}px`;
tip.style.top = `${rect.height * 0.06}px`;
};
const onLeave = () => {
crossLine.setAttribute("visibility", "hidden");
tip.hidden = true;
};
svg.addEventListener("mousemove", onMove);
svg.addEventListener("mouseleave", onLeave);
root.appendChild(svg);
const legend = document.createElement("div");
legend.className = "hint";
legend.textContent = "图例:实线/虚线区分同色不同事件";
legend.textContent = "图例:实线/虚线区分同色不同事件 · 鼠标悬停查看明细";
root.appendChild(legend);
}
@@ -1831,6 +1919,8 @@ async function pollReservations() {
`;
container.appendChild(info);
updateTabBadge("reservations", reservations.length);
if (reservations.length === 0) {
const hint = document.createElement("div");
hint.className = "hint";