精修 WebUI 第十九轮:sticky elevation + toggle switch + 步进按钮

- sectionTitle sticky 真贴顶时(IntersectionObserver + sentinel rootMargin -65px)加 .isStuck 类,浮起 0 6px 12px 阴影
- 关键开关升级为 toggle switch:.check.isToggle 把 input[type=checkbox] 渲染成 32×18 滑块(slider 配 14×14 圆点 + 0.18 阴影);3 个总控开关接入:infinite_loop_enabled / yanghao_enabled / yanghao_enable_actions / yanghao_only
- fmtDuration 改 mono 格式:HH:MM:SS / MM:SS(padStart),适配 tabular-nums
- 自绘 number stepper:所有 .input[type=number] 自动包 .numStepperWrap,hover/focus 时右侧浮现 ▲▼ 微按钮(18×12 双按钮组),调用 stepUp/stepDown + 派发 input/change;inline2 内不加避免连体冲突
- cache-bust v21 → v22
This commit is contained in:
Codex committed 2026-05-21 09:29:38 +08:00
1 parent f16eadbd75
commit cea5f1df45
3 files changed
+190 -9

No files matched your search

+61 -3
View File
@@ -555,6 +555,23 @@ function initShotFullscreen() {
});
}
function initStickySectionShadow() {
// 当 .sectionTitle 真正贴住 sticky top 时加 .isStuck 类
const titles = Array.from(document.querySelectorAll(".sectionTitle"))
.filter((el) => !el.matches(".cardTitle, summary, summary *"));
if (!titles.length || !("IntersectionObserver" in window)) return;
const io = new IntersectionObserver(
(entries) => {
for (const e of entries) {
// intersectionRatio < 1 && top 已到达 sentinel:贴住状态
e.target.classList.toggle("isStuck", e.intersectionRatio < 1 && e.boundingClientRect.top <= 65);
}
},
{ threshold: [1], rootMargin: "-65px 0px 0px 0px" }
);
titles.forEach((t) => io.observe(t));
}
function initShortcutsHelp() {
const isMac = /Mac|iPhone|iPad|iPod/i.test(navigator.platform || navigator.userAgent || "");
const mod = isMac ? "⌘" : "Ctrl";
@@ -843,6 +860,44 @@ function renderActionsLog() {
el.scrollTop = el.scrollHeight;
}
function attachNumberSteppers() {
// 给所有 .input[type=number] 包裹 .numStepperWrap + 添加 +/- 按钮
const SVG_UP = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 15 12 9 18 15"/></svg>';
const SVG_DOWN = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>';
document.querySelectorAll('input.input[type="number"]').forEach((input) => {
if (input.dataset.stepperBound === "1") return;
if (input.closest(".inline2")) return; // inline2 内不加,避免连体边框冲突
input.dataset.stepperBound = "1";
const wrap = document.createElement("div");
wrap.className = "numStepperWrap";
input.parentNode.insertBefore(wrap, input);
wrap.appendChild(input);
const btns = document.createElement("span");
btns.className = "numStepperBtns";
const up = document.createElement("button");
up.type = "button";
up.tabIndex = -1;
up.className = "numStepperBtn";
up.setAttribute("aria-label", "增加");
up.innerHTML = SVG_UP;
const down = document.createElement("button");
down.type = "button";
down.tabIndex = -1;
down.className = "numStepperBtn";
down.setAttribute("aria-label", "减少");
down.innerHTML = SVG_DOWN;
btns.append(up, down);
wrap.appendChild(btns);
const fire = (dir) => {
try { dir > 0 ? input.stepUp() : input.stepDown(); } catch (_) {}
input.dispatchEvent(new Event("input", { bubbles: true }));
input.dispatchEvent(new Event("change", { bubbles: true }));
};
up.addEventListener("click", (e) => { e.preventDefault(); fire(1); });
down.addEventListener("click", (e) => { e.preventDefault(); fire(-1); });
});
}
function fmtTime(ts) {
if (!ts) return "-";
try {
@@ -857,9 +912,10 @@ function fmtDuration(seconds) {
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
if (h > 0) return `${h}小时${m}分${sec}秒`;
if (m > 0) return `${m}分${sec}秒`;
return `${sec}秒`;
const pad = (n) => String(n).padStart(2, "0");
// mono 格式:HH:MM:SS(>1h)/ MM:SS(其他),方便 tabular-nums 对齐
if (h > 0) return `${pad(h)}:${pad(m)}:${pad(sec)}`;
return `${pad(m)}:${pad(sec)}`;
}
function pollShot() {
@@ -2266,6 +2322,8 @@ window.addEventListener("DOMContentLoaded", async () => {
initHeaderScroll();
initKeyboardShortcuts();
initShortcutsHelp();
initStickySectionShadow();
attachNumberSteppers();
startReservationsCountdownTick();
// 首屏统计数字加骨架,待第一次 pollStats 成功后移除
document.querySelectorAll(".stat .statValue").forEach((el) => {