diff --git a/lib/common/static/options_review.js b/lib/common/static/options_review.js index 20727f7..a7c3b21 100644 --- a/lib/common/static/options_review.js +++ b/lib/common/static/options_review.js @@ -10,6 +10,19 @@ options_options: "期期对冲记录", perp_options: "永期对冲记录", }; + var FORM_PRESETS = { + option_spot: { + strategy: ["顺势", "反转"], + direction: ["多", "空"], + entry: ["假突破", "结构突破"], + }, + hedge: { + strategy: ["横盘", "趋势"], + direction: ["多", "空"], + entry: ["横盘博弈方向", "趋势对冲止损"], + }, + }; + var RESULT_OPTIONS = ["盈利", "亏损", "持平"]; var activeSource = "option_spot"; var currentTradeId = null; var draftId = ""; @@ -80,6 +93,81 @@ loadStats(); } + function isHedgeSource(sourceType) { + return sourceType === "options_options" || sourceType === "perp_options"; + } + + function fillSelect(el, options, placeholder) { + if (!el) return; + var keep = el.value; + el.innerHTML = ""; + var first = document.createElement("option"); + first.value = ""; + first.textContent = placeholder || ""; + el.appendChild(first); + (options || []).forEach(function (v) { + var opt = document.createElement("option"); + opt.value = v; + opt.textContent = v; + el.appendChild(opt); + }); + if (keep) setSelectValue(el, keep); + } + + function setSelectValue(el, value) { + if (!el) return; + var v = value == null ? "" : String(value); + if (!v) { + el.value = ""; + return; + } + var found = false; + for (var i = 0; i < el.options.length; i++) { + if (el.options[i].value === v) { + found = true; + break; + } + } + if (!found) { + var opt = document.createElement("option"); + opt.value = v; + opt.textContent = v; + el.appendChild(opt); + } + el.value = v; + } + + function applyFormPresets(sourceType) { + var preset = isHedgeSource(sourceType) ? FORM_PRESETS.hedge : FORM_PRESETS.option_spot; + fillSelect($("or-f-strategy"), preset.strategy, "策略标签"); + fillSelect($("or-f-direction"), preset.direction, "方向判断"); + fillSelect($("or-f-entry"), preset.entry, "入场逻辑"); + fillSelect($("or-f-result"), RESULT_OPTIONS, "结果标签"); + } + + function autoDirection(t) { + if (!t) return ""; + if (isHedgeSource(t.source_type)) { + var d = String(t.direction || "").trim().toLowerCase(); + if (d === "long" || d === "buy" || d === "多") return "多"; + if (d === "short" || d === "sell" || d === "空") return "空"; + return ""; + } + var ot = String(t.opt_type || "").trim().toUpperCase(); + if (ot === "C" || ot === "CALL") return "多"; + if (ot === "P" || ot === "PUT") return "空"; + return ""; + } + + function autoResultTag(pnl) { + if (pnl == null || pnl === "") return ""; + var n = Number(pnl); + if (Number.isNaN(n)) return ""; + if (n > 0) return "盈利"; + if (n < 0) return "亏损"; + return "持平"; + } + function setActiveTab(source) { activeSource = source || "option_spot"; document.querySelectorAll(".or-tab").forEach(function (btn) { @@ -87,6 +175,7 @@ }); var title = $("or-list-title"); if (title) title.textContent = TAB_LABELS[activeSource] || "记录"; + applyFormPresets(activeSource); hideJournalForm(); reloadAll(); } @@ -429,6 +518,7 @@ function fillForm(t) { var e = t.entry || {}; + applyFormPresets(t.source_type || activeSource); ($("or-trade-id") || {}).value = String(t.id || ""); ($("or-f-open") || {}).value = toLocalInput(t.opened_at); ($("or-f-close") || {}).value = toLocalInput(t.closed_at); @@ -439,12 +529,12 @@ : (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 || ""; + setSelectValue($("or-f-strategy"), e.strategy_tag || ""); + setSelectValue($("or-f-direction"), e.direction_view || autoDirection(t)); ($("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 || ""; + setSelectValue($("or-f-result"), e.result_tag || autoResultTag(t.realized_pnl_total)); + setSelectValue($("or-f-entry"), e.entry_logic || ""); ($("or-f-note") || {}).value = e.note || ""; setMoodTags(e.mistake_tags); @@ -533,7 +623,7 @@ } var strategy = (($("or-f-strategy") || {}).value || "").trim(); if (!strategy) { - alert("请填写策略标签"); + alert("请选择策略标签"); return; } var payload = { diff --git a/lib/options/templates/options_review_panel.html b/lib/options/templates/options_review_panel.html index c32bac6..2233909 100644 --- a/lib/options/templates/options_review_panel.html +++ b/lib/options/templates/options_review_panel.html @@ -83,8 +83,12 @@
- - + + - +
- +
@@ -168,4 +179,4 @@
- +