Add refresh buttons to hub plan and calculator pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 01:43:27 +08:00
parent 384d404bb3
commit 3e8ecbf712
3 changed files with 89 additions and 5 deletions
+36 -2
View File
@@ -349,6 +349,31 @@
await Promise.all([loadActive(), loadHistory(), loadStats()]);
}
function fmtRefreshTime() {
const d = new Date();
const h = String(d.getHours()).padStart(2, "0");
const m = String(d.getMinutes()).padStart(2, "0");
const s = String(d.getSeconds()).padStart(2, "0");
return h + ":" + m + ":" + s;
}
async function refreshPage() {
const btn = $("plan-btn-refresh");
const status = $("plan-refresh-status");
if (btn) btn.disabled = true;
if (status) status.textContent = "刷新中…";
try {
await loadMeta();
await refreshAll();
if (status) status.textContent = "已刷新 " + fmtRefreshTime();
} catch (e) {
toast(e.message || "刷新失败", true);
if (status) status.textContent = "刷新失败";
} finally {
if (btn) btn.disabled = false;
}
}
function readCreateForm() {
const dir = document.querySelector('input[name="plan-direction"]:checked');
return {
@@ -524,6 +549,13 @@
}
function bindEvents() {
const refreshBtn = $("plan-btn-refresh");
if (refreshBtn) {
refreshBtn.addEventListener("click", function () {
void refreshPage();
});
}
const createForm = $("plan-create-form");
if (createForm) {
createForm.addEventListener("submit", function (ev) {
@@ -719,7 +751,7 @@
async function init() {
if (inited) {
await refreshAll();
await refreshPage();
return;
}
inited = true;
@@ -727,6 +759,8 @@
try {
await loadMeta();
await refreshAll();
const status = $("plan-refresh-status");
if (status) status.textContent = "已刷新 " + fmtRefreshTime();
} catch (e) {
toast(e.message || "加载失败", true);
}
@@ -734,5 +768,5 @@
function destroy() {}
window.hubPlanPage = { init: init, destroy: destroy };
window.hubPlanPage = { init: init, refresh: refreshPage, destroy: destroy };
})();