Refresh env UI on trade-mode change; hide hedge review tabs in options mode.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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__);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user