diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js
index 2e38cc0..9b89753 100644
--- a/lib/common/static/options_panel.js
+++ b/lib/common/static/options_panel.js
@@ -19,6 +19,8 @@
orderQuote: null,
expandedPosInst: null,
posTab: "live",
+ /** 未点设定前的目标输入草稿,避免持仓轮询重绘清空 */
+ targetDraftByInst: {},
};
let lastGoodPositions = null;
@@ -897,7 +899,8 @@
' data-prem="' + (prem != null ? prem : "") + '"' +
' data-armed-target="' + (armed ? tgt : "") + '">' +
'委托' +
- '' +
+ '' +
'' +
'" +
(armed
@@ -1021,6 +1024,12 @@
container.querySelectorAll(".opt-pos-target-input").forEach(function (inp) {
inp.addEventListener("click", function (e) { e.stopPropagation(); });
inp.addEventListener("input", function () {
+ const instId = inp.getAttribute("data-inst") || "";
+ const draft = String(inp.value || "");
+ if (instId) {
+ if (draft.trim() === "") delete state.targetDraftByInst[instId];
+ else state.targetDraftByInst[instId] = draft;
+ }
updatePosTargetEstimate(inp.closest(".opt-target-row"));
});
inp.addEventListener("keydown", function (e) {
@@ -1030,6 +1039,8 @@
setPositionTarget(inp.getAttribute("data-inst"), null);
}
});
+ // 重绘后恢复预估展示(草稿或已设定目标)
+ updatePosTargetEstimate(inp.closest(".opt-target-row"));
});
container.querySelectorAll(".opt-pos-bar").forEach(function (bar) {
bar.addEventListener("click", function () {
@@ -1068,6 +1079,7 @@
alert(d.msg || "设定失败");
return;
}
+ delete state.targetDraftByInst[inst];
if (inp) inp.value = "";
if (row) {
row.setAttribute("data-armed-target", String(tgt));
@@ -1092,6 +1104,7 @@
alert(d.msg || "取消失败");
return;
}
+ delete state.targetDraftByInst[inst];
await refreshAllPositions();
} finally {
if (btn) btn.disabled = false;
@@ -1224,6 +1237,13 @@
const empty = document.getElementById("opt-pos-empty");
const livePane = document.getElementById("opt-pos-live");
if (!wrap) return;
+ const active = document.activeElement;
+ const draftFocusInst =
+ active && active.classList && active.classList.contains("opt-pos-target-input")
+ ? active.getAttribute("data-inst")
+ : null;
+ const draftSelStart = draftFocusInst != null ? active.selectionStart : null;
+ const draftSelEnd = draftFocusInst != null ? active.selectionEnd : null;
wrap.innerHTML = "";
if (!list.length) {
if (empty) empty.style.display = "";
@@ -1257,6 +1277,17 @@
if (window.OptionsExpiryCountdown && OptionsExpiryCountdown.ensureTimer) {
OptionsExpiryCountdown.ensureTimer();
}
+ if (draftFocusInst) {
+ const reinp = wrap.querySelector('.opt-pos-target-input[data-inst="' + draftFocusInst + '"]');
+ if (reinp) {
+ reinp.focus();
+ try {
+ if (draftSelStart != null && draftSelEnd != null) {
+ reinp.setSelectionRange(draftSelStart, draftSelEnd);
+ }
+ } catch (e) { /* ignore */ }
+ }
+ }
}
async function refreshPositions() {