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
+ ? '
'
+ : "";
- 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 = "保存失败";