feat(hub): click archive trade row to switch chart

When the K-line panel is open, clicking a trade row switches selection and chart markers without re-fetching candles for the same symbol.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-11 20:10:56 +08:00
parent 3ef0750ea9
commit 035060b68a
3 changed files with 67 additions and 7 deletions
+3
View File
@@ -5797,6 +5797,9 @@ body.funds-fullscreen-open {
background: var(--panel);
}
.archive-trade-row {
cursor: default;
}
#page-archive.is-chart-open .archive-trade-row {
cursor: pointer;
}
.archive-trade-row.is-active {
+62 -5
View File
@@ -945,6 +945,50 @@
);
}
function isTradeRowInteractiveTarget(el) {
return !!(
el &&
el.closest &&
el.closest("button, select, input, textarea, a, label, .archive-actions-cell")
);
}
async function switchToTrade(tr) {
if (!tr) return;
const exKey = String(tr.exchange_key || "").toLowerCase();
const sym = tr.symbol || "";
if (!exKey || !sym) {
setStatus("该笔交易缺少交易所或合约,无法切换");
return;
}
const key = tradeRowKey(tr);
const prevEx = selected && selected.exchange_key;
const prevSym = selected && selected.symbol;
if (key === selectedTradeKey && prevEx === exKey && prevSym === sym) return;
selected = { exchange_key: exKey, symbol: sym };
selectedTradeKey = key;
renderTrades();
const needSymbolReload = prevEx !== exKey || prevSym !== sym;
if (needSymbolReload) {
await loadSymbolTradesForChart(exKey, sym);
}
if (!isChartOpen()) return;
if (needSymbolReload) {
await loadChart();
return;
}
applyChartMarkers();
const anchor = pickAnchorTrade();
if (anchor && lastCandles.length) {
focusInitialTradeView(lastCandles, anchor, timeframe);
}
updateChartTitle();
setStatus("已切换至 " + sym + " · " + exchangeLabel(exKey));
}
async function openTradeChart(tr) {
if (!tr) return;
const exKey = String(tr.exchange_key || "").toLowerCase();
@@ -953,12 +997,8 @@
setStatus("该笔交易缺少交易所或合约,无法加载图表");
return;
}
selected = { exchange_key: exKey, symbol: sym };
selectedTradeKey = tradeRowKey(tr);
renderTrades();
setChartOpen(true);
await loadSymbolTradesForChart(exKey, sym);
await loadChart();
await switchToTrade(tr);
}
function renderTrades() {
@@ -1080,14 +1120,31 @@
}
});
});
elTrades.querySelectorAll(".archive-trade-row").forEach(function (row) {
row.addEventListener("click", function (ev) {
if (!isChartOpen()) return;
if (isTradeRowInteractiveTarget(ev.target)) return;
const tr = findTradeByKey(row.getAttribute("data-key"));
if (tr) void switchToTrade(tr);
});
});
elTrades.querySelectorAll(".archive-tag-select").forEach(function (sel) {
applyTagSelectStyle(sel);
sel.addEventListener("mousedown", function (ev) {
ev.stopPropagation();
});
sel.addEventListener("change", function () {
applyTagSelectStyle(sel);
saveOverlay(sel.getAttribute("data-id"), sel.getAttribute("data-ex"), sel.value, null);
});
});
elTrades.querySelectorAll(".archive-note-input").forEach(function (inp) {
inp.addEventListener("mousedown", function (ev) {
ev.stopPropagation();
});
inp.addEventListener("click", function (ev) {
ev.stopPropagation();
});
inp.addEventListener("change", function () {
const row = inp.closest(".archive-trade-row");
const tagSel = row && row.querySelector(".archive-tag-select");
+2 -2
View File
@@ -15,7 +15,7 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Orbitron:wght@500;600;700&display=swap" rel="stylesheet" media="print" onload="this.media='all'" />
<noscript><link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Orbitron:wght@500;600;700&display=swap" rel="stylesheet" /></noscript>
<link rel="stylesheet" href="/assets/app.css?v=20260612-archive-chart-row" />
<link rel="stylesheet" href="/assets/app.css?v=20260612-trade-row-click" />
<link rel="stylesheet" href="/assets/dashboard.css?v=20260612-dash-monitor-count" />
</head>
<body>
@@ -584,7 +584,7 @@
<script src="https://unpkg.com/lightweight-charts@4.2.0/dist/lightweight-charts.standalone.production.js"></script>
<script src="/assets/chart_draw.js?v=20260609-market-day-split"></script>
<script src="/assets/chart.js?v=20260609-market-day-split"></script>
<script src="/assets/archive.js?v=20260612-trade-row-key"></script>
<script src="/assets/archive.js?v=20260612-trade-row-click"></script>
<script src="/assets/funds.js?v=20260609-hub-funds-fold"></script>
<script src="/assets/dashboard.js?v=20260612-dash-monitor-count"></script>
<script src="/assets/ai_review_render.js?v=3"></script>