Skip to content

Commit 844eca6

Browse files
committed
全页面动态刷新:按视图感知自动更新 + 切回标签页立即刷新 (v1.7.2)
- 自动刷新定时器覆盖所有数据页面:总览/中转站整页重载, 用量统计与我的站点只替换正文区域(筛选控件与滚动位置不受影响) - 切回浏览器标签页(visibilitychange)时立即刷新当前视图,不等下个周期 - 设置/通知页保持跳过:有未保存表单,自动重绘会清空输入
1 parent f874363 commit 844eca6

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "relay-monitor",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"private": true,
55
"description": "监控 sub2api / new-api 中转站余额的网页面板",
66
"type": "module",

public/app.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,15 @@ $("#refreshBtn").onclick = (e) => doRefreshAll(e.currentTarget);
17131713
// 后台数据更新只在这两个数据视图上触发重绘
17141714
const isDataView = () => state.view === "dashboard" || state.view === "stations";
17151715

1716+
// 按当前视图刷新数据:用量/我的站点只替换正文区域,筛选控件不受影响;
1717+
// 设置/通知页有表单,跳过自动重绘
1718+
function refreshCurrentView() {
1719+
if (isDataView()) return reload().catch(() => {});
1720+
if (state.view === "usage") return loadUsage(true);
1721+
if (state.view === "own") return loadOwn(true);
1722+
return Promise.resolve();
1723+
}
1724+
17161725
async function doRefreshAll(btn) {
17171726
btn?.classList.add("spin");
17181727
try {
@@ -1740,9 +1749,14 @@ async function loadNotifications() {
17401749
function startAuto() {
17411750
if (autoTimer) clearInterval(autoTimer);
17421751
const sec = Math.max(10, state.settings.refreshIntervalSec || 60);
1743-
autoTimer = setInterval(() => { if (isDataView()) reload().catch(() => {}); }, sec * 1000);
1752+
autoTimer = setInterval(refreshCurrentView, sec * 1000);
17441753
}
17451754

1755+
// 切回浏览器标签页时立即刷新一次,不用等下个周期
1756+
document.addEventListener("visibilitychange", () => {
1757+
if (!document.hidden && state.user && $("#loginScreen").hidden) refreshCurrentView();
1758+
});
1759+
17461760
async function bootData() {
17471761
const meta = await api.meta();
17481762
state.types = meta.types;

0 commit comments

Comments
 (0)