Fix double POST on open position in embed shell mode.
Embed capture-phase form handler and allowManualOrderSubmit both submitted /add_order; skip custom forms and use a single fetch reload path. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -889,6 +889,10 @@ function cancelExchangeTpsl(orderId, role){
|
|||||||
|
|
||||||
function allowManualOrderSubmit(form){
|
function allowManualOrderSubmit(form){
|
||||||
form.dataset.rrOk = "1";
|
form.dataset.rrOk = "1";
|
||||||
|
if(document.body && document.body.getAttribute("data-embed-shell") === "1" && window.InstanceEmbed && window.InstanceEmbed.postFormAndReload){
|
||||||
|
window.InstanceEmbed.postFormAndReload(form, "开仓提交中…");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(window.FormSubmitGuard){
|
if(window.FormSubmitGuard){
|
||||||
if(FormSubmitGuard.isLocked(form)){
|
if(FormSubmitGuard.isLocked(form)){
|
||||||
FormSubmitGuard.setSubmitLabel(form, "开仓提交中…");
|
FormSubmitGuard.setSubmitLabel(form, "开仓提交中…");
|
||||||
|
|||||||
@@ -115,6 +115,6 @@
|
|||||||
<script src="/static/manual_order_rr_preview.js?v=3"></script>
|
<script src="/static/manual_order_rr_preview.js?v=3"></script>
|
||||||
<script src="/static/key_monitor_form.js?v=1"></script>
|
<script src="/static/key_monitor_form.js?v=1"></script>
|
||||||
{% include 'embed_boot_scripts.html' %}
|
{% include 'embed_boot_scripts.html' %}
|
||||||
<script src="/static/instance_embed.js?v=3"></script>
|
<script src="/static/instance_embed.js?v=4"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
let navToken = 0;
|
let navToken = 0;
|
||||||
let loadingTab = false;
|
let loadingTab = false;
|
||||||
|
|
||||||
|
/** 自带校验后 form.submit() 的表单,勿在捕获阶段再 fetch 一份(会双发 POST) */
|
||||||
|
const CUSTOM_SUBMIT_FORM_IDS = new Set(["add-order-form", "key-form"]);
|
||||||
|
|
||||||
function isEmbedShell() {
|
function isEmbedShell() {
|
||||||
return document.body && document.body.getAttribute("data-embed-shell") === "1";
|
return document.body && document.body.getAttribute("data-embed-shell") === "1";
|
||||||
}
|
}
|
||||||
@@ -124,6 +127,26 @@
|
|||||||
return loadTab(getTab(), { replace: true, skipUrl: true });
|
return loadTab(getTab(), { replace: true, skipUrl: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postFormAndReload(form, label) {
|
||||||
|
if (!form) return Promise.resolve();
|
||||||
|
if (global.FormSubmitGuard) {
|
||||||
|
if (global.FormSubmitGuard.isLocked(form)) {
|
||||||
|
global.FormSubmitGuard.setSubmitLabel(form, label || "提交中…");
|
||||||
|
} else {
|
||||||
|
global.FormSubmitGuard.lock(form, label || "提交中…");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const fd = new FormData(form);
|
||||||
|
return fetch(form.action, {
|
||||||
|
method: form.method || "POST",
|
||||||
|
body: fd,
|
||||||
|
credentials: "same-origin",
|
||||||
|
redirect: "manual",
|
||||||
|
})
|
||||||
|
.then(() => reloadCurrentTab())
|
||||||
|
.catch(() => reloadCurrentTab());
|
||||||
|
}
|
||||||
|
|
||||||
function patchApplyListWindow() {
|
function patchApplyListWindow() {
|
||||||
if (typeof global.applyListWindow !== "function") return;
|
if (typeof global.applyListWindow !== "function") return;
|
||||||
global.applyListWindow = function embedApplyListWindow() {
|
global.applyListWindow = function embedApplyListWindow() {
|
||||||
@@ -176,6 +199,7 @@
|
|||||||
const form = ev.target;
|
const form = ev.target;
|
||||||
if (!(form instanceof HTMLFormElement)) return;
|
if (!(form instanceof HTMLFormElement)) return;
|
||||||
if (form.method && form.method.toUpperCase() === "GET") return;
|
if (form.method && form.method.toUpperCase() === "GET") return;
|
||||||
|
if (CUSTOM_SUBMIT_FORM_IDS.has(form.id)) return;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const fd = new FormData(form);
|
const fd = new FormData(form);
|
||||||
fetch(form.action, {
|
fetch(form.action, {
|
||||||
@@ -221,6 +245,7 @@
|
|||||||
loadTab,
|
loadTab,
|
||||||
reloadCurrentTab,
|
reloadCurrentTab,
|
||||||
getTab,
|
getTab,
|
||||||
|
postFormAndReload,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.readyState === "loading") {
|
if (document.readyState === "loading") {
|
||||||
|
|||||||
@@ -74,6 +74,20 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submitKeyForm(keyForm, label) {
|
||||||
|
if (
|
||||||
|
document.body &&
|
||||||
|
document.body.getAttribute("data-embed-shell") === "1" &&
|
||||||
|
global.InstanceEmbed &&
|
||||||
|
typeof global.InstanceEmbed.postFormAndReload === "function"
|
||||||
|
) {
|
||||||
|
global.InstanceEmbed.postFormAndReload(keyForm, label || "提交中…");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (global.FormSubmitGuard) global.FormSubmitGuard.nativeSubmitOnce(keyForm, label || "提交中…");
|
||||||
|
else keyForm.submit();
|
||||||
|
}
|
||||||
|
|
||||||
function bindKeyMonitorForm() {
|
function bindKeyMonitorForm() {
|
||||||
const keyForm = document.getElementById("key-form");
|
const keyForm = document.getElementById("key-form");
|
||||||
const keyTypeSel = document.querySelector('#key-form [name="type"]');
|
const keyTypeSel = document.querySelector('#key-form [name="type"]');
|
||||||
@@ -103,8 +117,7 @@
|
|||||||
}
|
}
|
||||||
const typeVal = (keyForm.querySelector('[name="type"]') || {}).value || "";
|
const typeVal = (keyForm.querySelector('[name="type"]') || {}).value || "";
|
||||||
if (typeVal === "假突破") {
|
if (typeVal === "假突破") {
|
||||||
if (global.FormSubmitGuard) global.FormSubmitGuard.nativeSubmitOnce(keyForm, "提交中…");
|
submitKeyForm(keyForm, "提交中…");
|
||||||
else keyForm.submit();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (global.FormSubmitGuard) global.FormSubmitGuard.lock(keyForm, "校验排名中…");
|
if (global.FormSubmitGuard) global.FormSubmitGuard.lock(keyForm, "校验排名中…");
|
||||||
@@ -125,8 +138,7 @@
|
|||||||
if (global.FormSubmitGuard) global.FormSubmitGuard.unlock(keyForm);
|
if (global.FormSubmitGuard) global.FormSubmitGuard.unlock(keyForm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (global.FormSubmitGuard) global.FormSubmitGuard.nativeSubmitOnce(keyForm, "提交中…");
|
submitKeyForm(keyForm, "提交中…");
|
||||||
else keyForm.submit();
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
alert("日成交量排名检查失败,请稍后重试");
|
alert("日成交量排名检查失败,请稍后重试");
|
||||||
|
|||||||
Reference in New Issue
Block a user