Add refresh buttons to hub plan and calculator pages.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 () {},
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user