From a38a89e2743cd74ac4667eca8692871cb98d2ba6 Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 15 Sep 2026 11:28:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=9F=E6=9D=83=E5=A4=8D?= =?UTF-8?q?=E7=9B=98=E4=BF=9D=E5=AD=98=E5=90=8E=E7=AB=8B=E5=88=BB=E5=BC=B9?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=97=B6=E8=87=AA=E5=8A=A8K=E7=BA=BF?= =?UTF-8?q?=E5=B0=9A=E6=9C=AA=E7=94=9F=E6=88=90=E5=B0=B1=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=9C=AA=E4=B8=8A=E4=BC=A0=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- lib/common/static/options_review.js | 102 +++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 10 deletions(-) diff --git a/lib/common/static/options_review.js b/lib/common/static/options_review.js index 0ef3f3b..c7cf7f3 100644 --- a/lib/common/static/options_review.js +++ b/lib/common/static/options_review.js @@ -582,31 +582,103 @@ } } + var detailChartPollTimer = null; + var detailChartPollTradeId = 0; + function hideDetail() { hideLightbox(); + stopDetailChartPoll(); var backdrop = $("or-detail-backdrop"); if (backdrop) backdrop.hidden = true; } - function openDetail(tradeId) { + function stopDetailChartPoll() { + if (detailChartPollTimer) { + clearTimeout(detailChartPollTimer); + detailChartPollTimer = null; + } + detailChartPollTradeId = 0; + } + + function tradeHasAutoChart(t) { + var images = ((t && t.entry) || {}).images || []; + for (var i = 0; i < images.length; i++) { + var tf = String((images[i] && images[i].tf) || "").trim(); + var file = String((images[i] && images[i].file) || "").trim(); + if (tf === "auto" && file) return true; + } + return false; + } + + function openDetail(tradeId, opts) { + opts = opts || {}; + var waitAuto = !!opts.waitAutoChart; var backdrop = $("or-detail-backdrop"); if (!backdrop) return; + stopDetailChartPoll(); backdrop.hidden = false; ($("or-detail-title") || {}).textContent = "加载中…"; ($("or-detail-meta") || {}).innerHTML = ""; ($("or-detail-text") || {}).innerHTML = ""; - ($("or-detail-images") || {}).innerHTML = ""; + ($("or-detail-images") || {}).innerHTML = waitAuto + ? '
自动K线
生成中…
' + : ""; - fetch("/api/options/review/trades/" + tradeId, { credentials: "same-origin" }) - .then(function (r) { + function applyTrade(trade, pendingAuto) { + renderDetail(trade, { pendingAuto: !!pendingAuto }); + } + + function fetchOnce() { + return fetch("/api/options/review/trades/" + tradeId, { + credentials: "same-origin", + }).then(function (r) { return r.json(); - }) + }); + } + + fetchOnce() .then(function (data) { if (!data.ok || !data.trade) { ($("or-detail-title") || {}).textContent = "加载失败"; return; } - renderDetail(data.trade); + if (!waitAuto || tradeHasAutoChart(data.trade)) { + applyTrade(data.trade, false); + return; + } + applyTrade(data.trade, true); + detailChartPollTradeId = tradeId; + var tries = 0; + var maxTries = 20; + function poll() { + if (detailChartPollTradeId !== tradeId) return; + tries += 1; + fetchOnce() + .then(function (again) { + if (detailChartPollTradeId !== tradeId) return; + if (again.ok && again.trade && tradeHasAutoChart(again.trade)) { + stopDetailChartPoll(); + applyTrade(again.trade, false); + loadReviewed({ sync: false, soft: true }); + return; + } + if (tries >= maxTries) { + stopDetailChartPoll(); + applyTrade((again && again.trade) || data.trade, false); + return; + } + detailChartPollTimer = setTimeout(poll, 1500); + }) + .catch(function () { + if (detailChartPollTradeId !== tradeId) return; + if (tries >= maxTries) { + stopDetailChartPoll(); + return; + } + detailChartPollTimer = setTimeout(poll, 1500); + }); + } + detailChartPollTimer = setTimeout(poll, 1200); }) .catch(function () { ($("or-detail-title") || {}).textContent = "加载失败"; @@ -644,9 +716,11 @@ if (cb) cb.checked = false; } - function renderDetailImages(images) { + function renderDetailImages(images, opts) { var imagesHost = $("or-detail-images"); if (!imagesHost) return; + opts = opts || {}; + var pendingAuto = !!opts.pendingAuto; var byTf = {}; (images || []).forEach(function (img) { var tf = String((img && img.tf) || "").trim(); @@ -657,6 +731,14 @@ }); // 互斥:有自动K线只显示自动;否则只显示手动四周期 var hasAuto = !!byTf.auto; + if (pendingAuto && !hasAuto) { + imagesHost.innerHTML = + '
' + + '自动K线' + + '
生成中…
' + + "
"; + return; + } var order = hasAuto ? ["auto"] : ["5m", "15m", "1h", "4h"]; var keys = order.slice(); if (!hasAuto) { @@ -721,7 +803,7 @@ }); } - function renderDetail(t) { + function renderDetail(t, opts) { var e = t.entry || {}; reviewedCache[t.id] = t; ($("or-detail-title") || {}).textContent = @@ -805,7 +887,7 @@ var imagesHost = $("or-detail-images"); if (imagesHost) { - renderDetailImages(e.images || []); + renderDetailImages(e.images || [], opts || {}); } } @@ -1225,7 +1307,7 @@ : "已保存"; hideJournalForm(); reloadAll(); - openDetail(tradeId); + openDetail(tradeId, { waitAutoChart: !!data.chart_queued }); }) .catch(function () { ($("or-save-status") || {}).textContent = "保存失败";