diff --git a/manual_trading_hub/static/calculator.js b/manual_trading_hub/static/calculator.js index a7a2c28..db8ea3e 100644 --- a/manual_trading_hub/static/calculator.js +++ b/manual_trading_hub/static/calculator.js @@ -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 () {}, }; })(); diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index a4c262d..443c86f 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -66,6 +66,10 @@

PLN 开仓计划

计划录入 · 进行中跟踪 · 历史归档与胜率统计

+
+ + +
+
+ + +

趋势回调计算器

@@ -1039,8 +1047,8 @@ - - + + diff --git a/manual_trading_hub/static/plan.js b/manual_trading_hub/static/plan.js index 8310b92..992c432 100644 --- a/manual_trading_hub/static/plan.js +++ b/manual_trading_hub/static/plan.js @@ -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 }; })();