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
+43 -1
View File
@@ -188,6 +188,37 @@
fillExchangeSelect($("calc-roll-exchange"));
}
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 = $("calc-btn-refresh");
const status = $("calc-refresh-status");
const trendId = $("calc-trend-exchange") && $("calc-trend-exchange").value;
const rollId = $("calc-roll-exchange") && $("calc-roll-exchange").value;
if (btn) btn.disabled = true;
if (status) status.textContent = "刷新中…";
Object.keys(marketCache).forEach(function (k) {
delete marketCache[k];
});
try {
await loadCalculatorExchanges();
fillExchangeSelect($("calc-trend-exchange"), trendId);
fillExchangeSelect($("calc-roll-exchange"), rollId);
await Promise.all([refreshMarket("calc-trend"), refreshMarket("calc-roll")]);
if (status) status.textContent = "已刷新 " + fmtRefreshTime();
} catch (err) {
if (status) status.textContent = "刷新失败";
} finally {
if (btn) btn.disabled = false;
}
}
function bindMarket(prefix) {
const exchangeEl = $(prefix + "-exchange");
const baseEl = $(prefix + "-base");
@@ -557,12 +588,23 @@
bindRollLegsUI();
bindMarket("calc-trend");
bindMarket("calc-roll");
const refreshBtn = $("calc-btn-refresh");
if (refreshBtn) {
refreshBtn.addEventListener("click", function () {
void refreshPage();
});
}
}
window.hubCalculatorPage = {
init: function () {
bindOnce();
if (inited) {
void refreshPage();
return;
}
void bindOnce();
},
refresh: refreshPage,
destroy: function () {},
};
})();