行情区:OHLCV与现价栏移出画布,修复倒计时实时刷新

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 11:57:56 +08:00
parent 2f1ca6fb5a
commit 586465e64e
3 changed files with 77 additions and 42 deletions
+19 -5
View File
@@ -23,6 +23,8 @@
const elRefresh = document.getElementById("market-refresh");
const elStatus = document.getElementById("market-status");
const elUpdated = document.getElementById("market-updated");
const elBarCountdown = document.getElementById("market-bar-countdown");
const elPriceGutter = document.querySelector(".market-price-gutter");
const elO = document.getElementById("mkt-o");
const elH = document.getElementById("mkt-h");
const elL = document.getElementById("mkt-l");
@@ -160,8 +162,17 @@
updatePriceTag();
}
function tickLiveClock() {
const cd = fmtBarCountdown(barRemainMs(currentTf));
if (elPriceTagTime && elPriceTag && !elPriceTag.classList.contains("hidden")) {
elPriceTagTime.textContent = cd;
}
if (elBarCountdown) elBarCountdown.textContent = "距收盘 " + cd;
}
function updatePriceTag() {
if (!elPriceTag || !candleSeries || !chart) return;
tickLiveClock();
const bar = latestCandle();
if (!bar || bar.close == null) {
elPriceTag.classList.add("hidden");
@@ -174,7 +185,7 @@
} catch (e) {
y = null;
}
const hostH = chartHost.clientHeight || 0;
const hostH = (elPriceGutter && elPriceGutter.clientHeight) || chartHost.clientHeight || 0;
if (y == null || y < 8 || y > hostH - 8) {
elPriceTag.classList.add("hidden");
elPriceTag.setAttribute("aria-hidden", "true");
@@ -186,12 +197,12 @@
elPriceTag.setAttribute("aria-hidden", "false");
elPriceTag.style.top = y + "px";
if (elPriceTagValue) elPriceTagValue.textContent = fmtPrice(bar.close);
if (elPriceTagTime) elPriceTagTime.textContent = fmtBarCountdown(barRemainMs(currentTf));
}
function startPriceTagTimer() {
stopPriceTagTimer();
priceTagTimer = setInterval(updatePriceTag, 1000);
tickLiveClock();
priceTagTimer = setInterval(tickLiveClock, 1000);
}
function stopPriceTagTimer() {
@@ -519,7 +530,8 @@
elStatus.className = data.stale ? "market-status warn" : "market-status";
elStatus.textContent = hint;
}
if (elUpdated) elUpdated.textContent = data.updated_at || "--";
if (elUpdated) elUpdated.textContent = "数据 " + (data.updated_at || "--");
tickLiveClock();
} catch (e) {
if (myToken !== loadToken) return;
if (elStatus) {
@@ -537,6 +549,8 @@
}
if (elTf) {
elTf.addEventListener("change", function () {
currentTf = (elTf && elTf.value) || "1d";
tickLiveClock();
loadChart(false);
});
}
@@ -573,8 +587,8 @@
bind();
}
startAutoRefresh();
startPriceTagTimer();
await loadChart(false);
startPriceTagTimer();
},
reload: function (force) {
loadChart(!!force);