Skip to content

Commit ff78850

Browse files
committed
保存设置后立即刷新一轮余额
- 修改刷新间隔后原本要等满一个新周期才有第一次查询(设 360 秒就干等 6 分钟), 现在保存设置即触发一轮 refreshAll - 间隔未变化时(比如只改低余额阈值)不再重置轮询节拍 - 前端切回总览/中转站视图时后台拉一次最新数据,避免展示整周期前的缓存
1 parent 90b7c97 commit ff78850

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

public/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,11 @@ function drawChart(wrap, points, prediction) {
11351135
}
11361136

11371137
// ---- 事件委托 --------------------------------------------------------------
1138-
document.querySelectorAll(".nav-item").forEach((n) => (n.onclick = () => { state.view = n.dataset.view; render(); }));
1138+
document.querySelectorAll(".nav-item").forEach((n) => (n.onclick = () => {
1139+
state.view = n.dataset.view;
1140+
render(); // 先用缓存立即渲染
1141+
if (isDataView()) reload().catch(() => {}); // 切回数据视图时后台拉一次最新
1142+
}));
11391143

11401144
$(".main").addEventListener("click", async (e) => {
11411145
if (e.target.closest("#hdrAdd")) return openModal(null);

server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ app.put("/api/settings", async (req, res) => {
438438
patch.lowBalanceUsd = Math.max(0, Number(req.body.lowBalanceUsd) || 0);
439439
const settings = await store.updateSettings(patch);
440440
restartPolling();
441+
// 立即刷新一轮:重置定时器后第一次触发要等满整个周期,不主动刷会显得设置没生效
442+
refreshAll().catch(() => {});
441443
res.json({ settings });
442444
});
443445

@@ -471,9 +473,12 @@ app.use(express.static(join(__dirname, "public")));
471473
// ---------------------------------------------------------------------------
472474
let pollTimer = null;
473475
let pollRunning = false;
476+
let pollSec = 0;
474477
function restartPolling() {
475-
if (pollTimer) clearInterval(pollTimer);
476478
const sec = store.settings.refreshIntervalSec || 60;
479+
if (pollTimer && sec === pollSec) return; // 间隔没变(比如只改了阈值)就不重置节拍
480+
pollSec = sec;
481+
if (pollTimer) clearInterval(pollTimer);
477482
pollTimer = setInterval(() => {
478483
if (pollRunning) return; // 上一轮还没结束(慢站点超时可达几十秒)就跳过本轮
479484
pollRunning = true;

0 commit comments

Comments
 (0)