fix: 手动刷新提示结果并重置倒计时
This commit is contained in:
@@ -289,6 +289,11 @@ func (a *App) page(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (a *App) manualRefresh(w http.ResponseWriter, r *http.Request) {
|
func (a *App) manualRefresh(w http.ResponseWriter, r *http.Request) {
|
||||||
if a.isLoggedIn() {
|
if a.isLoggedIn() {
|
||||||
a.refresh()
|
a.refresh()
|
||||||
|
if a.isLoggedIn() {
|
||||||
|
a.stampNext()
|
||||||
|
a.wakeLoop()
|
||||||
|
a.save()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, a.view())
|
writeJSON(w, http.StatusOK, a.view())
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-8
@@ -52,6 +52,15 @@
|
|||||||
h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }
|
h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.03em; }
|
||||||
.menu { position: relative; }
|
.menu { position: relative; }
|
||||||
body.guest #menu { display: none; }
|
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 {
|
.menu-list {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
@@ -79,10 +88,27 @@
|
|||||||
.countdown[hidden] { display: none !important; }
|
.countdown[hidden] { display: none !important; }
|
||||||
.countdown {
|
.countdown {
|
||||||
color: rgba(255, 255, 255, 0.92);
|
color: rgba(255, 255, 255, 0.92);
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
font-variant-numeric: tabular-nums;
|
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 {
|
.mask {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@@ -237,7 +263,6 @@
|
|||||||
#pending { padding: 16px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
|
#pending { padding: 16px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
|
||||||
#dash.stale { opacity: 0.72; }
|
#dash.stale { opacity: 0.72; }
|
||||||
@media (max-width: 720px) {
|
@media (max-width: 720px) {
|
||||||
header { align-items: flex-start; flex-direction: column; }
|
|
||||||
.hero { grid-template-columns: 1fr; }
|
.hero { grid-template-columns: 1fr; }
|
||||||
.money, .traffic { grid-template-columns: 1fr 1fr; }
|
.money, .traffic { grid-template-columns: 1fr 1fr; }
|
||||||
.figure + .figure { border-left: 0; border-top: 1px solid var(--line); }
|
.figure + .figure { border-left: 0; border-top: 1px solid var(--line); }
|
||||||
@@ -255,7 +280,11 @@
|
|||||||
<header>
|
<header>
|
||||||
<h1>广电账户</h1>
|
<h1>广电账户</h1>
|
||||||
<div class="menu" id="menu" hidden>
|
<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>
|
<div id="menuList" class="menu-list" hidden>
|
||||||
<button id="settingsBtn" type="button">设置</button>
|
<button id="settingsBtn" type="button">设置</button>
|
||||||
<button id="refresh" type="button">刷新</button>
|
<button id="refresh" type="button">刷新</button>
|
||||||
@@ -265,6 +294,7 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<p id="error" class="banner" hidden></p>
|
<p id="error" class="banner" hidden></p>
|
||||||
|
<div id="toast" class="toast" hidden></div>
|
||||||
|
|
||||||
<section id="login" class="card">
|
<section id="login" class="card">
|
||||||
<h2>登录</h2>
|
<h2>登录</h2>
|
||||||
@@ -572,7 +602,17 @@
|
|||||||
const m = String(Math.floor(left / 60)).padStart(2, "0");
|
const m = String(Math.floor(left / 60)).padStart(2, "0");
|
||||||
const s = String(left % 60).padStart(2, "0");
|
const s = String(left % 60).padStart(2, "0");
|
||||||
el.hidden = false;
|
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() {
|
function closeMenu() {
|
||||||
@@ -717,11 +757,14 @@
|
|||||||
$("refresh").disabled = true;
|
$("refresh").disabled = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/refresh", { method: "POST" });
|
const res = await fetch("/api/refresh", { method: "POST" });
|
||||||
|
const data = await res.json();
|
||||||
lastKey = "";
|
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) {
|
} catch (err) {
|
||||||
$("error").hidden = false;
|
toast("刷新失败");
|
||||||
$("error").textContent = "刷新失败";
|
|
||||||
} finally {
|
} finally {
|
||||||
$("refresh").disabled = false;
|
$("refresh").disabled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user