fix: 手动刷新提示结果并重置倒计时

This commit is contained in:
2026-10-12 18:45:11 +08:00
parent 92b5621a51
commit 24cffd7c56
2 changed files with 56 additions and 8 deletions
+51 -8
View File
@@ -52,6 +52,15 @@
h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }
.menu { position: relative; }
body.guest #menu { display: none; }
#menuBtn {
width: 32px;
height: 32px;
padding: 0;
display: inline-flex;
align-items: center;
justify-content: center;
}
#menuBtn svg { display: block; }
.menu-list {
position: absolute;
right: 0;
@@ -79,10 +88,27 @@
.countdown[hidden] { display: none !important; }
.countdown {
color: rgba(255, 255, 255, 0.92);
font-size: 13px;
font-size: 12px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.04em;
letter-spacing: 0;
white-space: nowrap;
}
.toast {
position: fixed;
left: 50%;
bottom: 28px;
transform: translateX(-50%);
z-index: 30;
max-width: min(420px, calc(100% - 32px));
padding: 8px 14px;
border-radius: 8px;
background: #1b2433;
color: #fff;
font-size: 13px;
box-shadow: var(--shadow);
}
.toast.bad { background: #8f2d24; }
.toast[hidden] { display: none; }
.mask {
position: fixed;
inset: 0;
@@ -237,7 +263,6 @@
#pending { padding: 16px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
#dash.stale { opacity: 0.72; }
@media (max-width: 720px) {
header { align-items: flex-start; flex-direction: column; }
.hero { grid-template-columns: 1fr; }
.money, .traffic { grid-template-columns: 1fr 1fr; }
.figure + .figure { border-left: 0; border-top: 1px solid var(--line); }
@@ -255,7 +280,11 @@
<header>
<h1>广电账户</h1>
<div class="menu" id="menu" hidden>
<button id="menuBtn" type="button" aria-expanded="false" aria-controls="menuList">更多</button>
<button id="menuBtn" type="button" aria-expanded="false" aria-controls="menuList" aria-label="更多">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
<path d="M2 4h12M2 8h12M2 12h12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>
</svg>
</button>
<div id="menuList" class="menu-list" hidden>
<button id="settingsBtn" type="button">设置</button>
<button id="refresh" type="button">刷新</button>
@@ -265,6 +294,7 @@
</header>
<p id="error" class="banner" hidden></p>
<div id="toast" class="toast" hidden></div>
<section id="login" class="card">
<h2>登录</h2>
@@ -572,7 +602,17 @@
const m = String(Math.floor(left / 60)).padStart(2, "0");
const s = String(left % 60).padStart(2, "0");
el.hidden = false;
el.textContent = m + ":" + s;
el.textContent = "刷新: " + m + ":" + s;
}
let toastTimer = 0;
function toast(text, ok) {
const el = $("toast");
el.textContent = text;
el.className = ok ? "toast" : "toast bad";
el.hidden = false;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => { el.hidden = true; }, 2200);
}
function closeMenu() {
@@ -717,11 +757,14 @@
$("refresh").disabled = true;
try {
const res = await fetch("/api/refresh", { method: "POST" });
const data = await res.json();
lastKey = "";
render(await res.json());
render(data);
if (!res.ok || !data.loggedIn) toast(data.error || "刷新失败");
else if (data.error) toast(data.error);
else toast("刷新成功", true);
} catch (err) {
$("error").hidden = false;
$("error").textContent = "刷新失败";
toast("刷新失败");
} finally {
$("refresh").disabled = false;
}