修复翻倍倍数输入被刷回1:持仓轮询重绘时保留草稿,聚焦输入时跳过重绘。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-12 16:20:45 +08:00
parent 2a33f74252
commit 86cf722117
2 changed files with 38 additions and 6 deletions
+37 -5
View File
@@ -28,6 +28,8 @@
posTab: "live",
/** 未点设定前的目标输入草稿,避免持仓轮询重绘清空 */
targetDraftByInst: {},
/** 翻倍倍数草稿,避免轮询重绘把正在输入的值刷回 1 */
profitExitDraftByInst: {},
};
let lastGoodPositions = null;
@@ -1556,21 +1558,28 @@
return "";
}
const enabled = !!p.profit_exit_enabled;
const mult = p.profit_exit_mult != null && Number(p.profit_exit_mult) > 0
const serverMult = p.profit_exit_mult != null && Number(p.profit_exit_mult) > 0
? Number(p.profit_exit_mult)
: 1;
const state = String(p.profit_exit_state || (enabled ? "active" : "idle"));
const draft = state.profitExitDraftByInst[inst];
const multDisp = draft != null && String(draft).trim() !== ""
? String(draft)
: String(serverMult);
const multNum = Number(multDisp);
const multLabel = formatProfitExitMultLabel(
Number.isFinite(multNum) && multNum > 0 ? multNum : serverMult
);
const statePe = String(p.profit_exit_state || (enabled ? "active" : "idle"));
const req = p.profit_exit_required_recycle;
const multLabel = formatProfitExitMultLabel(mult);
let statusTxt = enabled ? ("监控中 · " + multLabel) : "未开启";
if (enabled && state === "closing") statusTxt = "平仓挂单中 · " + multLabel;
if (enabled && statePe === "closing") statusTxt = "平仓挂单中 · " + multLabel;
return (
'<div class="opt-target-row opt-profit-exit-pos-row" data-inst="' + inst + '">' +
'<span class="opt-target-row-label">翻倍</span>' +
'<label class="opt-profit-exit-toggle"><input type="checkbox" class="opt-pos-profit-exit-enabled" data-inst="' +
inst + '"' + (enabled ? " checked" : "") + "> 开启</label>" +
'<input type="number" class="opt-pos-profit-exit-mult" data-inst="' + inst +
'" min="0.1" step="0.1" value="' + mult +
'" min="0.1" step="0.1" value="' + multDisp +
'" autocomplete="off" inputmode="decimal" data-lpignore="true" data-1p-ignore="true">' +
'<button type="button" class="btn-secondary opt-profit-exit-save-btn" data-inst="' +
inst + '" data-mode="' + (enabled ? "cancel" : "apply") + '">' +
@@ -1799,6 +1808,13 @@
inp.addEventListener("click", function (e) { e.stopPropagation(); });
inp.addEventListener("mousedown", function (e) { e.stopPropagation(); });
inp.addEventListener("focus", function (e) { e.stopPropagation(); });
inp.addEventListener("input", function () {
const id = inp.getAttribute("data-inst") || "";
if (!id) return;
const draft = String(inp.value || "");
if (draft.trim() === "") delete state.profitExitDraftByInst[id];
else state.profitExitDraftByInst[id] = draft;
});
inp.addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault();
@@ -1930,6 +1946,7 @@
alert(d.msg || "保存失败");
return;
}
delete state.profitExitDraftByInst[inst];
await refreshAllPositions();
} finally {
if (btn) btn.disabled = false;
@@ -2083,6 +2100,14 @@
}
return;
}
// 正在输入翻倍倍数:同样跳过重绘,避免被默认 1 冲掉
if (active && active.classList && active.classList.contains("opt-pos-profit-exit-mult")) {
const focusInst = active.getAttribute("data-inst") || "";
if (focusInst) {
state.profitExitDraftByInst[focusInst] = String(active.value || "");
}
return;
}
// 未聚焦时也同步可见输入,防止漏掉 input 事件
wrap.querySelectorAll(".opt-pos-target-input").forEach(function (inp) {
const id = inp.getAttribute("data-inst") || "";
@@ -2091,6 +2116,13 @@
if (v.trim() === "") delete state.targetDraftByInst[id];
else state.targetDraftByInst[id] = v;
});
wrap.querySelectorAll(".opt-pos-profit-exit-mult").forEach(function (inp) {
const id = inp.getAttribute("data-inst") || "";
if (!id) return;
const v = String(inp.value || "");
if (v.trim() === "") delete state.profitExitDraftByInst[id];
else state.profitExitDraftByInst[id] = v;
});
wrap.innerHTML = "";
if (!list.length) {
if (empty) empty.style.display = "";
+1 -1
View File
@@ -350,4 +350,4 @@
</div>
</div>
<script src="/static/options_expiry_countdown.js?v=1"></script>
<script src="/static/options_panel.js?v=63"></script>
<script src="/static/options_panel.js?v=64"></script>