From fdbbde08dfec7edadf0ad7be782a6e46b70b9a17 Mon Sep 17 00:00:00 2001 From: dekun Date: Thu, 30 Jul 2026 08:38:19 +0800 Subject: [PATCH] Refresh env UI on trade-mode change; hide hedge review tabs in options mode. Co-authored-by: Cursor --- lib/common/static/instance_settings_prefs.js | 42 +++++++++++++++++-- lib/common/static/options_review.js | 18 +++++++- lib/instance/templates/embed_shell.html | 2 +- lib/instance/templates/env_config_panel.html | 6 ++- lib/instance/templates/index.html | 2 +- .../templates/options_review_panel.html | 16 +++++-- 6 files changed, 74 insertions(+), 12 deletions(-) diff --git a/lib/common/static/instance_settings_prefs.js b/lib/common/static/instance_settings_prefs.js index c2d0ea6..e9fec9b 100644 --- a/lib/common/static/instance_settings_prefs.js +++ b/lib/common/static/instance_settings_prefs.js @@ -311,7 +311,9 @@ const panelsWrap = document.createElement("div"); panelsWrap.className = "env-config-panels"; panelsWrap.id = "env-config-grid"; + let modeSectionIdx = 0; groups.forEach((group, idx) => { + if ((group.title || "").indexOf("期权/对冲模式") >= 0) modeSectionIdx = idx; const label = document.createElement("label"); label.className = "env-tab-btn"; label.htmlFor = "env-sec-" + idx; @@ -328,16 +330,47 @@ panel.appendChild(hint); } const grid = document.createElement("div"); - grid.className = "env-form-grid"; + grid.className = "env-config-grid"; (group.fields || []).forEach((field) => grid.appendChild(renderEnvFieldRow(field))); panel.appendChild(grid); panelsWrap.appendChild(panel); }); body.appendChild(tabBar); body.appendChild(panelsWrap); + body.dataset.envModeSectionIdx = String(modeSectionIdx); + bindTradeModeAutoRefresh(body); return body; } + function bindTradeModeAutoRefresh(body) { + const modeSel = body.querySelector('.env-field-input[data-env-key="OKX_TRADE_MODE"]'); + if (!modeSel || modeSel.dataset.modeRefreshBound === "1") return; + modeSel.dataset.modeRefreshBound = "1"; + modeSel.addEventListener("change", async () => { + const status = document.getElementById("env-config-status"); + const nextMode = modeSel.value; + setStatus(status, "切换交易模式并刷新配置…"); + try { + await fetchJson("/api/settings/env", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ values: { OKX_TRADE_MODE: nextMode } }), + }); + await loadEnvConfig(true); + const page = envConfigRoot() || document.querySelector(".env-config-page"); + const newBody = page && page.querySelector("#env-config-body"); + const idx = newBody && newBody.dataset.envModeSectionIdx; + if (idx != null) { + const radio = document.getElementById("env-sec-" + idx); + if (radio) radio.checked = true; + } + setStatus(status, "交易模式已切换为当前选项,配置区已刷新"); + } catch (e) { + setStatus(status, e.message || "切换失败", true); + } + }); + } + async function loadEnvConfig(force) { const root = envConfigRoot(); const body = root && root.querySelector("#env-config-body"); @@ -395,10 +428,10 @@ setStatus(status, "已保存,正在重启实例…"); await restartInstance(); setStatus(status, "保存并重启完成"); - await loadEnvConfig(); + await loadEnvConfig(true); } else { setStatus(status, "已保存(即时生效项已应用)"); - await loadEnvConfig(); + await loadEnvConfig(true); } } catch (e) { setStatus(status, e.message || "保存失败", true); @@ -501,6 +534,9 @@ bindEvents(); loadDisplayPrefsForm(false); loadEnvConfig(false); + const root = envConfigRoot(); + const body = root && root.querySelector("#env-config-body"); + if (body) bindTradeModeAutoRefresh(body); if (global.__INSTANCE_DISPLAY__) applyDisplayToNav(global.__INSTANCE_DISPLAY__); } diff --git a/lib/common/static/options_review.js b/lib/common/static/options_review.js index 126fad4..d4d7e49 100644 --- a/lib/common/static/options_review.js +++ b/lib/common/static/options_review.js @@ -248,8 +248,22 @@ return "持平"; } + function tradeModeFromDom() { + var tabs = document.querySelector(".or-tabs"); + return (tabs && tabs.getAttribute("data-okx-trade-mode")) || "options"; + } + + function defaultSourceForMode(mode) { + if (mode === "options_options") return "options_options"; + if (mode === "perp_options") return "perp_options"; + return "option_spot"; + } + function setActiveTab(source) { - activeSource = source || "option_spot"; + var mode = tradeModeFromDom(); + var allowed = defaultSourceForMode(mode); + activeSource = source || allowed; + if (activeSource !== allowed) activeSource = allowed; tradesPage = 0; reviewedPage = 0; document.querySelectorAll(".or-tab").forEach(function (btn) { @@ -1312,7 +1326,7 @@ hideJournalForm(); hideDetail(); hardenSearchAutofill(); - setActiveTab("option_spot"); + setActiveTab(defaultSourceForMode(tradeModeFromDom())); } function hardenSearchAutofill() { diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 80648a8..fa6ab28 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -166,7 +166,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj - + diff --git a/lib/instance/templates/env_config_panel.html b/lib/instance/templates/env_config_panel.html index 4e5d70e..3b35269 100644 --- a/lib/instance/templates/env_config_panel.html +++ b/lib/instance/templates/env_config_panel.html @@ -16,7 +16,11 @@ {% if env_config_groups %} -
+ {% set ns = namespace(mode_idx=0) %} + {% for group in env_config_groups %} + {% if '期权/对冲模式' in (group.title or '') %}{% set ns.mode_idx = loop.index0 %}{% endif %} + {% endfor %} +
{% for group in env_config_groups %} {% endfor %} diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index b97af41..e0f46fe 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -1983,6 +1983,6 @@ document.addEventListener("DOMContentLoaded", function () { }); {% endif %} - + \ No newline at end of file diff --git a/lib/options/templates/options_review_panel.html b/lib/options/templates/options_review_panel.html index f909d96..f67311b 100644 --- a/lib/options/templates/options_review_panel.html +++ b/lib/options/templates/options_review_panel.html @@ -185,10 +185,16 @@ {# Tab + 筛选:放在各内容卡片上方,全局作用于下方列表/统计 #}
-
+
+ {% if okx_trade_mode|default('options') == 'options' %} - - + {% elif okx_trade_mode == 'options_options' %} + + {% elif okx_trade_mode == 'perp_options' %} + + {% else %} + + {% endif %}
+ {% if okx_trade_mode|default('options') == 'options' %} + {% endif %}
@@ -408,4 +416,4 @@
- +