Improve options review tabs and multi-timeframe uploads.
Add source-type tabs, open an inline journal form from list rows, and match contract-style 5m/15m/1h/4h screenshot slots. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+291
-217
@@ -1,13 +1,19 @@
|
||||
/**
|
||||
* OKX 期权复盘(含对冲):列表 / 同步 / 统计 / 编辑上传.
|
||||
* OKX 期权复盘:三类 Tab + 列表点选 + 下方多周期(5m/15m/1h/4h)复盘表单.
|
||||
*/
|
||||
(function (global) {
|
||||
"use strict";
|
||||
|
||||
var SLOT_TFS = ["chart", "entry", "exit", "other"];
|
||||
var SLOT_LABELS = { chart: "走势图", entry: "入场", exit: "离场", other: "其他" };
|
||||
var SLOT_TFS = ["5m", "15m", "1h", "4h"];
|
||||
var TAB_LABELS = {
|
||||
option_spot: "期权交易记录",
|
||||
options_options: "期期对冲记录",
|
||||
perp_options: "永期对冲记录",
|
||||
};
|
||||
var activeSource = "option_spot";
|
||||
var currentTradeId = null;
|
||||
var draftId = "";
|
||||
var tradesCache = {};
|
||||
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
@@ -17,8 +23,7 @@
|
||||
if (v == null || v === "") return "—";
|
||||
var n = Number(v);
|
||||
if (Number.isNaN(n)) return "—";
|
||||
var s = (n >= 0 ? "+" : "") + n.toFixed(2);
|
||||
return s;
|
||||
return (n >= 0 ? "+" : "") + n.toFixed(2);
|
||||
}
|
||||
|
||||
function fmtHold(sec) {
|
||||
@@ -29,24 +34,11 @@
|
||||
return (s / 86400).toFixed(1) + "d";
|
||||
}
|
||||
|
||||
function qs() {
|
||||
var p = new URLSearchParams();
|
||||
var source = ($("or-filter-source") || {}).value || "";
|
||||
var uly = ($("or-filter-uly") || {}).value || "";
|
||||
var opt = ($("or-filter-opt") || {}).value || "";
|
||||
var reviewed = ($("or-filter-reviewed") || {}).value || "";
|
||||
var strategy = (($("or-filter-strategy") || {}).value || "").trim();
|
||||
var from = ($("or-filter-from") || {}).value || "";
|
||||
var to = ($("or-filter-to") || {}).value || "";
|
||||
if (source) p.set("source_type", source);
|
||||
if (uly) p.set("underlying", uly);
|
||||
if (opt) p.set("opt_type", opt);
|
||||
if (reviewed) p.set("reviewed", reviewed);
|
||||
if (strategy) p.set("strategy_tag", strategy);
|
||||
if (from) p.set("closed_from", from.replace("T", " ") + ":00");
|
||||
if (to) p.set("closed_to", to.replace("T", " ") + ":00");
|
||||
if (($("or-include-hedge-legs") || {}).checked) p.set("include_hedge_legs", "1");
|
||||
return p.toString();
|
||||
function toLocalInput(ts) {
|
||||
if (!ts) return "";
|
||||
var s = String(ts).trim().replace(" ", "T");
|
||||
if (s.length >= 16) return s.slice(0, 16);
|
||||
return s;
|
||||
}
|
||||
|
||||
function newDraftId() {
|
||||
@@ -58,6 +50,25 @@
|
||||
return s;
|
||||
}
|
||||
|
||||
function qs() {
|
||||
var p = new URLSearchParams();
|
||||
p.set("source_type", activeSource);
|
||||
var uly = ($("or-filter-uly") || {}).value || "";
|
||||
var opt = ($("or-filter-opt") || {}).value || "";
|
||||
var reviewed = ($("or-filter-reviewed") || {}).value || "";
|
||||
var strategy = (($("or-filter-strategy") || {}).value || "").trim();
|
||||
var from = ($("or-filter-from") || {}).value || "";
|
||||
var to = ($("or-filter-to") || {}).value || "";
|
||||
if (uly) p.set("underlying", uly);
|
||||
if (opt) p.set("opt_type", opt);
|
||||
if (reviewed) p.set("reviewed", reviewed);
|
||||
if (strategy) p.set("strategy_tag", strategy);
|
||||
if (from) p.set("closed_from", from.replace("T", " ") + ":00");
|
||||
if (to) p.set("closed_to", to.replace("T", " ") + ":00");
|
||||
if (($("or-include-hedge-legs") || {}).checked) p.set("include_hedge_legs", "1");
|
||||
return p.toString();
|
||||
}
|
||||
|
||||
function setSyncStatus(text) {
|
||||
var el = $("or-sync-status");
|
||||
if (el) el.textContent = text || "";
|
||||
@@ -93,6 +104,17 @@
|
||||
});
|
||||
}
|
||||
|
||||
function setActiveTab(source) {
|
||||
activeSource = source || "option_spot";
|
||||
document.querySelectorAll(".or-tab").forEach(function (btn) {
|
||||
btn.classList.toggle("active", btn.getAttribute("data-source") === activeSource);
|
||||
});
|
||||
var title = $("or-list-title");
|
||||
if (title) title.textContent = TAB_LABELS[activeSource] || "记录";
|
||||
hideJournalForm();
|
||||
reloadAll();
|
||||
}
|
||||
|
||||
function reloadAll() {
|
||||
loadTrades();
|
||||
loadStats();
|
||||
@@ -101,23 +123,25 @@
|
||||
function loadTrades() {
|
||||
var tbody = $("or-trades-tbody");
|
||||
if (!tbody) return;
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="muted">加载中…</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="muted">加载中…</td></tr>';
|
||||
fetch("/api/options/review/trades?" + qs(), { credentials: "same-origin" })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="muted">加载失败</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="muted">加载失败</td></tr>';
|
||||
return;
|
||||
}
|
||||
var rows = data.trades || [];
|
||||
tradesCache = {};
|
||||
if (!rows.length) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="muted">暂无记录,请先同步</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="muted">暂无记录,请先同步</td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = rows
|
||||
.map(function (t) {
|
||||
tradesCache[t.id] = t;
|
||||
var title =
|
||||
t.source_type === "option_spot"
|
||||
? t.inst_id || "—"
|
||||
@@ -130,22 +154,25 @@
|
||||
: Number(t.realized_pnl_total) < 0
|
||||
? "color:#f07178"
|
||||
: "";
|
||||
var active = currentTradeId === t.id ? " or-row-active" : "";
|
||||
return (
|
||||
"<tr data-id=\"" +
|
||||
'<tr class="or-trade-row' +
|
||||
active +
|
||||
'" data-id="' +
|
||||
t.id +
|
||||
"\">" +
|
||||
'">' +
|
||||
"<td><span class=\"or-badge\">" +
|
||||
(t.source_label || t.source_type) +
|
||||
"</span></td>" +
|
||||
"<td>" +
|
||||
title +
|
||||
"</td>" +
|
||||
"<td style=\"" +
|
||||
'<td style="' +
|
||||
pnlClass +
|
||||
"\">" +
|
||||
'">' +
|
||||
fmtPnl(t.realized_pnl_total) +
|
||||
"</td>" +
|
||||
"<td class=\"muted\" style=\"font-size:12px\">" +
|
||||
'<td class="muted" style="font-size:12px">' +
|
||||
(t.opened_at || "—") +
|
||||
"<br>" +
|
||||
(t.closed_at || "—") +
|
||||
@@ -159,21 +186,18 @@
|
||||
"<td>" +
|
||||
(t.reviewed ? "已复盘" : "待复盘") +
|
||||
"</td>" +
|
||||
"<td><button type=\"button\" class=\"btn-secondary or-edit-btn\" data-id=\"" +
|
||||
t.id +
|
||||
"\">复盘</button></td>" +
|
||||
"</tr>"
|
||||
);
|
||||
})
|
||||
.join("");
|
||||
tbody.querySelectorAll(".or-edit-btn").forEach(function (btn) {
|
||||
btn.addEventListener("click", function () {
|
||||
openEdit(Number(btn.getAttribute("data-id")));
|
||||
tbody.querySelectorAll(".or-trade-row").forEach(function (tr) {
|
||||
tr.addEventListener("click", function () {
|
||||
openJournalForm(Number(tr.getAttribute("data-id")));
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function () {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="muted">加载失败</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7" class="muted">加载失败</td></tr>';
|
||||
});
|
||||
}
|
||||
|
||||
@@ -189,7 +213,7 @@
|
||||
.slice(0, 8)
|
||||
.map(function (g) {
|
||||
return (
|
||||
"<div style=\"display:flex;justify-content:space-between;gap:8px;font-size:13px\">" +
|
||||
'<div style="display:flex;justify-content:space-between;gap:8px;font-size:13px">' +
|
||||
"<span>" +
|
||||
g.key +
|
||||
" · " +
|
||||
@@ -204,7 +228,13 @@
|
||||
);
|
||||
})
|
||||
.join("");
|
||||
return '<div class="or-stat-card"><div style="font-weight:600;margin-bottom:6px">' + title + "</div>" + lines + "</div>";
|
||||
return (
|
||||
'<div class="or-stat-card"><div style="font-weight:600;margin-bottom:6px">' +
|
||||
title +
|
||||
"</div>" +
|
||||
lines +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
|
||||
function loadStats() {
|
||||
@@ -248,197 +278,231 @@
|
||||
.catch(function () {});
|
||||
}
|
||||
|
||||
function uploadSlot(input, file) {
|
||||
if (!draftId || !file) return;
|
||||
var status = input.parentElement && input.parentElement.querySelector(".or-upload-status");
|
||||
var hidden = input.parentElement && input.parentElement.querySelector(".or-upload-hidden");
|
||||
if (status) status.textContent = "上传中…";
|
||||
var fd = new FormData();
|
||||
fd.append("draft_id", draftId);
|
||||
fd.append("tf", input.getAttribute("data-tf") || "");
|
||||
fd.append("file", file);
|
||||
fetch("/api/options/review/upload_slot", { method: "POST", body: fd, credentials: "same-origin" })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok) throw new Error(data.error || "fail");
|
||||
if (hidden) hidden.value = data.file;
|
||||
if (status) status.textContent = "已上传";
|
||||
input.value = "";
|
||||
})
|
||||
.catch(function () {
|
||||
if (hidden) hidden.value = "";
|
||||
if (status) status.textContent = "失败";
|
||||
});
|
||||
function resetUploadSlots() {
|
||||
draftId = newDraftId();
|
||||
var draftEl = $("or-draft-id");
|
||||
if (draftEl) draftEl.value = draftId;
|
||||
document.querySelectorAll("#or-upload-slots .or-upload-hidden").forEach(function (el) {
|
||||
el.value = "";
|
||||
});
|
||||
document.querySelectorAll("#or-upload-slots .or-upload-input").forEach(function (el) {
|
||||
el.value = "";
|
||||
});
|
||||
document.querySelectorAll("#or-upload-slots .or-upload-status").forEach(function (el) {
|
||||
el.textContent = "";
|
||||
});
|
||||
}
|
||||
|
||||
function openEdit(tradeId) {
|
||||
currentTradeId = tradeId;
|
||||
draftId = newDraftId();
|
||||
var modal = $("or-edit-modal");
|
||||
var body = $("or-edit-body");
|
||||
var title = $("or-edit-title");
|
||||
if (!modal || !body) return;
|
||||
body.innerHTML = '<div class="muted">加载中…</div>';
|
||||
modal.style.display = "flex";
|
||||
fetch("/api/options/review/trades/" + tradeId, { credentials: "same-origin" })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok || !data.trade) {
|
||||
body.innerHTML = '<div class="muted">加载失败</div>';
|
||||
function bindUploadSlots() {
|
||||
document.querySelectorAll("#or-upload-slots .or-upload-input").forEach(function (input) {
|
||||
if (input.dataset.orBound === "1") return;
|
||||
input.dataset.orBound = "1";
|
||||
input.addEventListener("change", function () {
|
||||
var file = input.files && input.files[0];
|
||||
var row = input.closest(".or-upload-row");
|
||||
var status = row && row.querySelector(".or-upload-status");
|
||||
var hidden = row && row.querySelector(".or-upload-hidden");
|
||||
if (!file) {
|
||||
if (hidden) hidden.value = "";
|
||||
if (status) status.textContent = "";
|
||||
return;
|
||||
}
|
||||
var t = data.trade;
|
||||
var e = t.entry || {};
|
||||
if (title) title.textContent = (t.source_label || "") + " · 复盘 #" + t.id;
|
||||
var legsHtml = "";
|
||||
if (t.legs && t.legs.length) {
|
||||
legsHtml =
|
||||
'<table class="options-strike-table" style="margin:8px 0"><thead><tr><th>腿</th><th>合约</th><th>盈亏</th><th>原因</th></tr></thead><tbody>' +
|
||||
t.legs
|
||||
.map(function (leg) {
|
||||
return (
|
||||
"<tr><td>" +
|
||||
(leg.leg_role || "") +
|
||||
"</td><td>" +
|
||||
(leg.inst_id || leg.symbol || "") +
|
||||
"</td><td>" +
|
||||
fmtPnl(leg.realized_pnl) +
|
||||
"</td><td>" +
|
||||
(leg.close_reason || "") +
|
||||
"</td></tr>"
|
||||
);
|
||||
})
|
||||
.join("") +
|
||||
"</tbody></table>";
|
||||
}
|
||||
var slots = SLOT_TFS.map(function (tf) {
|
||||
return (
|
||||
'<div class="or-upload-row" style="margin:6px 0">' +
|
||||
"<label>" +
|
||||
(SLOT_LABELS[tf] || tf) +
|
||||
' <input type="file" accept="image/*" class="or-upload-input" data-tf="' +
|
||||
tf +
|
||||
'">' +
|
||||
"</label>" +
|
||||
'<input type="hidden" class="or-upload-hidden" data-tf="' +
|
||||
tf +
|
||||
'">' +
|
||||
' <span class="or-upload-status muted"></span></div>'
|
||||
);
|
||||
}).join("");
|
||||
body.innerHTML =
|
||||
'<div class="muted" style="font-size:13px;margin-bottom:8px">' +
|
||||
(t.inst_id || t.underlying || "") +
|
||||
" · 盈亏 " +
|
||||
fmtPnl(t.realized_pnl_total) +
|
||||
(t.is_hedge
|
||||
? " (永续 " +
|
||||
fmtPnl(t.realized_pnl_perp) +
|
||||
" / 期权 " +
|
||||
fmtPnl(t.realized_pnl_options) +
|
||||
")"
|
||||
: "") +
|
||||
"<br>开 " +
|
||||
(t.opened_at || "—") +
|
||||
" → 平 " +
|
||||
(t.closed_at || "—") +
|
||||
"</div>" +
|
||||
legsHtml +
|
||||
'<div class="form-grid" style="display:grid;grid-template-columns:1fr 1fr;gap:8px">' +
|
||||
'<input id="or-f-strategy" placeholder="策略标签" value="' +
|
||||
esc(e.strategy_tag) +
|
||||
'">' +
|
||||
'<input id="or-f-direction" placeholder="方向判断" value="' +
|
||||
esc(e.direction_view) +
|
||||
'">' +
|
||||
'<input id="or-f-exit" placeholder="离场原因" value="' +
|
||||
esc(e.exit_reason) +
|
||||
'">' +
|
||||
'<select id="or-f-followed"><option value="">是否按计划</option>' +
|
||||
opt("是", e.followed_plan) +
|
||||
opt("否", e.followed_plan) +
|
||||
opt("部分", e.followed_plan) +
|
||||
"</select>" +
|
||||
'<input id="or-f-result" placeholder="结果标签" value="' +
|
||||
esc(e.result_tag) +
|
||||
'">' +
|
||||
'<input id="or-f-mistakes" placeholder="错误标签(逗号分隔)" value="' +
|
||||
esc(e.mistake_tags) +
|
||||
'">' +
|
||||
"</div>" +
|
||||
'<textarea id="or-f-entry" rows="2" placeholder="入场逻辑" style="width:100%;margin-top:8px">' +
|
||||
esc(e.entry_logic) +
|
||||
"</textarea>" +
|
||||
'<textarea id="or-f-note" rows="3" placeholder="复盘备注" style="width:100%;margin-top:8px">' +
|
||||
esc(e.note) +
|
||||
"</textarea>" +
|
||||
'<div style="margin-top:10px"><strong>截图</strong>' +
|
||||
slots +
|
||||
"</div>" +
|
||||
'<div class="form-row" style="margin-top:12px;gap:8px">' +
|
||||
'<button type="button" class="btn" id="or-save-btn">保存复盘</button>' +
|
||||
'<button type="button" class="btn-secondary" id="or-del-btn">删除复盘</button>' +
|
||||
"</div>";
|
||||
body.querySelectorAll(".or-upload-input").forEach(function (input) {
|
||||
input.addEventListener("change", function () {
|
||||
var file = input.files && input.files[0];
|
||||
if (file) uploadSlot(input, file);
|
||||
if (!draftId) draftId = newDraftId();
|
||||
if (status) status.textContent = "上传中…";
|
||||
var fd = new FormData();
|
||||
fd.append("draft_id", draftId);
|
||||
fd.append("tf", input.getAttribute("data-tf") || "");
|
||||
fd.append("file", file);
|
||||
fetch("/api/options/review/upload_slot", {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
credentials: "same-origin",
|
||||
})
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok) throw new Error(data.error || "fail");
|
||||
if (hidden) hidden.value = data.file;
|
||||
if (status) status.textContent = "上传成功 " + data.file;
|
||||
input.value = "";
|
||||
})
|
||||
.catch(function () {
|
||||
if (hidden) hidden.value = "";
|
||||
if (status) status.textContent = "上传失败";
|
||||
});
|
||||
});
|
||||
// 回填已有图片文件名到 hidden(仅展示状态)
|
||||
(e.images || []).forEach(function (img) {
|
||||
var hidden = body.querySelector('.or-upload-hidden[data-tf="' + img.tf + '"]');
|
||||
var status = hidden && hidden.parentElement.querySelector(".or-upload-status");
|
||||
if (hidden && img.file) {
|
||||
hidden.value = img.file;
|
||||
if (status) status.textContent = "已有 " + img.file;
|
||||
}
|
||||
});
|
||||
$("or-save-btn").addEventListener("click", saveEntry);
|
||||
$("or-del-btn").addEventListener("click", deleteEntry);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function esc(s) {
|
||||
return String(s == null ? "" : s)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/"/g, """);
|
||||
function setMoodTags(raw) {
|
||||
var set = {};
|
||||
String(raw || "")
|
||||
.split(/[,,]/)
|
||||
.map(function (x) {
|
||||
return x.trim();
|
||||
})
|
||||
.filter(Boolean)
|
||||
.forEach(function (x) {
|
||||
set[x] = true;
|
||||
});
|
||||
document.querySelectorAll(".or-mood").forEach(function (cb) {
|
||||
cb.checked = !!set[cb.value];
|
||||
});
|
||||
}
|
||||
|
||||
function opt(v, cur) {
|
||||
return '<option value="' + v + '"' + (cur === v ? " selected" : "") + ">" + v + "</option>";
|
||||
function collectMoodTags() {
|
||||
var out = [];
|
||||
document.querySelectorAll(".or-mood:checked").forEach(function (cb) {
|
||||
out.push(cb.value);
|
||||
});
|
||||
return out.join(",");
|
||||
}
|
||||
|
||||
function collectImages() {
|
||||
var body = $("or-edit-body");
|
||||
if (!body) return [];
|
||||
var out = [];
|
||||
body.querySelectorAll(".or-upload-hidden").forEach(function (el) {
|
||||
document.querySelectorAll("#or-upload-slots .or-upload-hidden").forEach(function (el) {
|
||||
var file = (el.value || "").trim();
|
||||
if (file) out.push({ tf: el.getAttribute("data-tf") || "", file: file });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
function hideJournalForm() {
|
||||
currentTradeId = null;
|
||||
var card = $("or-journal-card");
|
||||
if (card) card.hidden = true;
|
||||
document.querySelectorAll(".or-trade-row").forEach(function (tr) {
|
||||
tr.classList.remove("or-row-active");
|
||||
});
|
||||
}
|
||||
|
||||
function openJournalForm(tradeId) {
|
||||
currentTradeId = tradeId;
|
||||
var card = $("or-journal-card");
|
||||
if (!card) return;
|
||||
card.hidden = false;
|
||||
card.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
document.querySelectorAll(".or-trade-row").forEach(function (tr) {
|
||||
tr.classList.toggle("or-row-active", Number(tr.getAttribute("data-id")) === tradeId);
|
||||
});
|
||||
resetUploadSlots();
|
||||
bindUploadSlots();
|
||||
($("or-save-status") || {}).textContent = "加载中…";
|
||||
|
||||
fetch("/api/options/review/trades/" + tradeId, { credentials: "same-origin" })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok || !data.trade) {
|
||||
($("or-save-status") || {}).textContent = "加载失败";
|
||||
return;
|
||||
}
|
||||
fillForm(data.trade);
|
||||
($("or-save-status") || {}).textContent = "";
|
||||
})
|
||||
.catch(function () {
|
||||
($("or-save-status") || {}).textContent = "加载失败";
|
||||
});
|
||||
}
|
||||
|
||||
function fillForm(t) {
|
||||
var e = t.entry || {};
|
||||
($("or-trade-id") || {}).value = String(t.id || "");
|
||||
($("or-f-open") || {}).value = toLocalInput(t.opened_at);
|
||||
($("or-f-close") || {}).value = toLocalInput(t.closed_at);
|
||||
($("or-f-coin") || {}).value = t.underlying || "";
|
||||
($("or-f-inst") || {}).value =
|
||||
t.source_type === "option_spot"
|
||||
? t.inst_id || ""
|
||||
: (t.source_label || "") + (t.plan_close_reason ? " · " + t.plan_close_reason : "");
|
||||
($("or-f-pnl") || {}).value = fmtPnl(t.realized_pnl_total);
|
||||
($("or-f-hold") || {}).value = fmtHold(t.hold_seconds);
|
||||
($("or-f-strategy") || {}).value = e.strategy_tag || "";
|
||||
($("or-f-direction") || {}).value = e.direction_view || t.direction || "";
|
||||
($("or-f-exit") || {}).value = e.exit_reason || t.plan_close_reason || "";
|
||||
($("or-f-followed") || {}).value = e.followed_plan || "";
|
||||
($("or-f-result") || {}).value = e.result_tag || "";
|
||||
($("or-f-entry") || {}).value = e.entry_logic || "";
|
||||
($("or-f-note") || {}).value = e.note || "";
|
||||
setMoodTags(e.mistake_tags);
|
||||
|
||||
var summary = $("or-journal-summary");
|
||||
if (summary) {
|
||||
summary.textContent =
|
||||
(t.source_label || "") +
|
||||
" · " +
|
||||
(t.inst_id || t.underlying || "#" + t.id) +
|
||||
" · 盈亏 " +
|
||||
fmtPnl(t.realized_pnl_total) +
|
||||
(t.is_hedge
|
||||
? " (永续 " + fmtPnl(t.realized_pnl_perp) + " / 期权 " + fmtPnl(t.realized_pnl_options) + ")"
|
||||
: "");
|
||||
}
|
||||
|
||||
// 已有截图回填状态(文件名保留,新上传会换 draft)
|
||||
(e.images || []).forEach(function (img) {
|
||||
var hidden = document.querySelector(
|
||||
'#or-upload-slots .or-upload-hidden[data-tf="' + img.tf + '"]'
|
||||
);
|
||||
var status = document.querySelector(
|
||||
'#or-upload-slots .or-upload-status[data-tf="' + img.tf + '"]'
|
||||
);
|
||||
if (hidden && img.file) {
|
||||
hidden.value = img.file;
|
||||
if (status) status.textContent = "已有 " + img.file;
|
||||
}
|
||||
});
|
||||
|
||||
var legsHost = $("or-legs-host");
|
||||
if (legsHost) {
|
||||
if (t.legs && t.legs.length) {
|
||||
legsHost.innerHTML =
|
||||
"<h3>计划腿</h3><table class=\"options-strike-table\"><thead><tr><th>腿</th><th>合约</th><th>盈亏</th><th>原因</th></tr></thead><tbody>" +
|
||||
t.legs
|
||||
.map(function (leg) {
|
||||
return (
|
||||
"<tr><td>" +
|
||||
(leg.leg_role || "") +
|
||||
"</td><td>" +
|
||||
(leg.inst_id || leg.symbol || "") +
|
||||
"</td><td>" +
|
||||
fmtPnl(leg.realized_pnl) +
|
||||
"</td><td>" +
|
||||
(leg.close_reason || "") +
|
||||
"</td></tr>"
|
||||
);
|
||||
})
|
||||
.join("") +
|
||||
"</tbody></table>";
|
||||
} else {
|
||||
legsHost.innerHTML = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function saveEntry() {
|
||||
if (!currentTradeId) return;
|
||||
var tradeId = Number(($("or-trade-id") || {}).value || 0);
|
||||
if (!tradeId) return;
|
||||
var strategy = (($("or-f-strategy") || {}).value || "").trim();
|
||||
if (!strategy) {
|
||||
alert("请填写策略标签");
|
||||
return;
|
||||
}
|
||||
var payload = {
|
||||
trade_id: currentTradeId,
|
||||
strategy_tag: ($("or-f-strategy") || {}).value || "",
|
||||
trade_id: tradeId,
|
||||
strategy_tag: strategy,
|
||||
direction_view: ($("or-f-direction") || {}).value || "",
|
||||
exit_reason: ($("or-f-exit") || {}).value || "",
|
||||
followed_plan: ($("or-f-followed") || {}).value || "",
|
||||
result_tag: ($("or-f-result") || {}).value || "",
|
||||
mistake_tags: ($("or-f-mistakes") || {}).value || "",
|
||||
mistake_tags: collectMoodTags(),
|
||||
entry_logic: ($("or-f-entry") || {}).value || "",
|
||||
note: ($("or-f-note") || {}).value || "",
|
||||
images: collectImages(),
|
||||
};
|
||||
($("or-save-status") || {}).textContent = "保存中…";
|
||||
fetch("/api/options/review/entry", {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
@@ -450,21 +514,22 @@
|
||||
})
|
||||
.then(function (data) {
|
||||
if (!data.ok) {
|
||||
alert(data.msg || "保存失败");
|
||||
($("or-save-status") || {}).textContent = data.msg || "保存失败";
|
||||
return;
|
||||
}
|
||||
closeModal();
|
||||
($("or-save-status") || {}).textContent = "已保存";
|
||||
reloadAll();
|
||||
})
|
||||
.catch(function () {
|
||||
alert("保存失败");
|
||||
($("or-save-status") || {}).textContent = "保存失败";
|
||||
});
|
||||
}
|
||||
|
||||
function deleteEntry() {
|
||||
if (!currentTradeId) return;
|
||||
var tradeId = Number(($("or-trade-id") || {}).value || 0);
|
||||
if (!tradeId) return;
|
||||
if (!confirm("删除该条复盘内容与图片?")) return;
|
||||
fetch("/api/options/review/entry/" + currentTradeId, {
|
||||
fetch("/api/options/review/entry/" + tradeId, {
|
||||
method: "DELETE",
|
||||
credentials: "same-origin",
|
||||
})
|
||||
@@ -472,34 +537,43 @@
|
||||
return r.json();
|
||||
})
|
||||
.then(function () {
|
||||
closeModal();
|
||||
hideJournalForm();
|
||||
reloadAll();
|
||||
});
|
||||
}
|
||||
|
||||
function closeModal(ev) {
|
||||
if (ev && ev.target && ev.target.id !== "or-edit-modal") return;
|
||||
var modal = $("or-edit-modal");
|
||||
if (modal) modal.style.display = "none";
|
||||
currentTradeId = null;
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!$("options-review-root")) return;
|
||||
document.querySelectorAll(".or-tab").forEach(function (btn) {
|
||||
btn.addEventListener("click", function () {
|
||||
setActiveTab(btn.getAttribute("data-source"));
|
||||
});
|
||||
});
|
||||
var syncBtn = $("or-sync-btn");
|
||||
var reloadBtn = $("or-reload-btn");
|
||||
var saveBtn = $("or-save-btn");
|
||||
var clearBtn = $("or-clear-btn");
|
||||
var delBtn = $("or-del-btn");
|
||||
if (syncBtn) syncBtn.addEventListener("click", syncNow);
|
||||
if (reloadBtn) reloadBtn.addEventListener("click", reloadAll);
|
||||
["or-filter-source", "or-filter-uly", "or-filter-opt", "or-filter-reviewed", "or-include-hedge-legs"].forEach(
|
||||
if (saveBtn) saveBtn.addEventListener("click", saveEntry);
|
||||
if (clearBtn) clearBtn.addEventListener("click", hideJournalForm);
|
||||
if (delBtn) delBtn.addEventListener("click", deleteEntry);
|
||||
["or-filter-uly", "or-filter-opt", "or-filter-reviewed", "or-include-hedge-legs"].forEach(
|
||||
function (id) {
|
||||
var el = $(id);
|
||||
if (el) el.addEventListener("change", reloadAll);
|
||||
}
|
||||
);
|
||||
reloadAll();
|
||||
bindUploadSlots();
|
||||
setActiveTab("option_spot");
|
||||
}
|
||||
|
||||
global.OptionsReview = { init: init, closeModal: closeModal, openEdit: openEdit };
|
||||
global.OptionsReview = {
|
||||
init: init,
|
||||
openJournalForm: openJournalForm,
|
||||
hideJournalForm: hideJournalForm,
|
||||
};
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
Reference in New Issue
Block a user