feat条件单页本页划入交易户,避免跳转丢失新建表单。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+123
-12
@@ -202,6 +202,8 @@
|
||||
return m === "sim" || m === "live" ? m : "";
|
||||
}
|
||||
|
||||
var candidatesById = {};
|
||||
|
||||
function fmtTradingU(v) {
|
||||
if (v == null || v === "") return "—";
|
||||
const n = Number(v);
|
||||
@@ -232,6 +234,97 @@
|
||||
});
|
||||
}
|
||||
|
||||
function patchCandidateFunds(instanceId, tradingUsdt, fundingUsdt) {
|
||||
const id = String(instanceId);
|
||||
const it = candidatesById[id];
|
||||
if (it) {
|
||||
if (tradingUsdt != null) it.trading_usdt = tradingUsdt;
|
||||
if (fundingUsdt != null) it.funding_usdt = fundingUsdt;
|
||||
}
|
||||
const row = document.querySelector(
|
||||
'.cond-inst-row[data-inst-id="' + id.replace(/"/g, "") + '"]'
|
||||
);
|
||||
if (!row) return;
|
||||
const tradeEl = row.querySelector(".cond-inst-funds--trading");
|
||||
const fundEl = row.querySelector(".cond-inst-funds--funding");
|
||||
if (tradeEl) tradeEl.textContent = "交易 " + fmtTradingU(tradingUsdt);
|
||||
if (fundEl) fundEl.textContent = "资金 " + fmtTradingU(fundingUsdt);
|
||||
}
|
||||
|
||||
function transferFundingToTrading(instanceId) {
|
||||
const id = String(instanceId || "");
|
||||
const it = candidatesById[id];
|
||||
if (!it) return;
|
||||
if (!it.online) {
|
||||
window.alert("实例离线,无法划转");
|
||||
return;
|
||||
}
|
||||
if (it.transfer_blocked) {
|
||||
window.alert(it.transfer_block_msg || "当前不可划转");
|
||||
return;
|
||||
}
|
||||
const fund = Number(it.funding_usdt);
|
||||
const defAmt =
|
||||
!Number.isNaN(fund) && fund > 0 ? String(Math.round(fund * 10000) / 10000) : "";
|
||||
const raw = window.prompt("资金户 → 交易户(USDT)。本页划转,条件单表单不会丢失。", defAmt);
|
||||
if (raw == null) return;
|
||||
const amount = Number(String(raw).trim());
|
||||
if (!(amount > 0)) {
|
||||
window.alert("请输入大于 0 的数量");
|
||||
return;
|
||||
}
|
||||
const btn = document.querySelector(
|
||||
'.cond-inst-xfer[data-inst-id="' + id.replace(/"/g, "") + '"]'
|
||||
);
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = "划转中…";
|
||||
}
|
||||
fetch("/api/instances/" + encodeURIComponent(id) + "/transfer", {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
||||
body: JSON.stringify({
|
||||
amount: amount,
|
||||
from: "funding",
|
||||
to: "trading",
|
||||
ccy: "USDT",
|
||||
}),
|
||||
})
|
||||
.then(function (r) {
|
||||
return r.json().then(function (d) {
|
||||
return { http: r.status, d: d };
|
||||
});
|
||||
})
|
||||
.then(function (pack) {
|
||||
const d = pack.d || {};
|
||||
if (!d.ok) {
|
||||
window.alert(d.msg || "划转失败");
|
||||
return;
|
||||
}
|
||||
patchCandidateFunds(id, d.trading_usdt, d.funding_usdt);
|
||||
const st = document.getElementById("cf-status");
|
||||
if (st) {
|
||||
st.textContent =
|
||||
(it.name || id) +
|
||||
" 已划入交易 " +
|
||||
fmtTradingU(amount) +
|
||||
"(交易 " +
|
||||
fmtTradingU(d.trading_usdt) +
|
||||
")";
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
window.alert("划转请求失败");
|
||||
})
|
||||
.finally(function () {
|
||||
if (btn) {
|
||||
btn.disabled = !!(it.transfer_blocked || !it.online);
|
||||
btn.textContent = "划入交易";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderCandidateCard(it, checkedIds) {
|
||||
const disabled = !it.selectable;
|
||||
const tip = disabled
|
||||
@@ -245,13 +338,15 @@
|
||||
: "可选";
|
||||
const id = String(it.id);
|
||||
const checked = !disabled && checkedIds.indexOf(id) >= 0;
|
||||
const fundsTip =
|
||||
it.funding_usdt != null
|
||||
? "资金户 " + fmtTradingU(it.funding_usdt)
|
||||
: "";
|
||||
const xferBlocked = !!(it.transfer_blocked || !it.online);
|
||||
const xferTitle = xferBlocked
|
||||
? it.transfer_block_msg || (!it.online ? "离线" : "不可划转")
|
||||
: "资金户→交易户,本页完成不丢表单";
|
||||
return (
|
||||
'<div class="cond-inst-row' +
|
||||
(disabled ? " is-off" : "") +
|
||||
'" data-inst-id="' +
|
||||
escapeHtml(id) +
|
||||
'">' +
|
||||
'<label class="cond-inst' +
|
||||
(disabled ? " is-off" : "") +
|
||||
@@ -270,15 +365,23 @@
|
||||
'<span class="cond-inst-tag">' +
|
||||
escapeHtml(tip) +
|
||||
"</span>" +
|
||||
'<span class="cond-inst-funds" title="' +
|
||||
escapeHtml(fundsTip || "交易账户可用") +
|
||||
'">交易 ' +
|
||||
'<span class="cond-inst-funds cond-inst-funds--trading" title="交易账户可用">交易 ' +
|
||||
escapeHtml(fmtTradingU(it.trading_usdt)) +
|
||||
"</span>" +
|
||||
'<span class="cond-inst-funds cond-inst-funds--funding muted" title="资金账户可用">资金 ' +
|
||||
escapeHtml(fmtTradingU(it.funding_usdt)) +
|
||||
"</span>" +
|
||||
"</label>" +
|
||||
'<button type="button" class="btn btn-sm cond-inst-open" data-inst-id="' +
|
||||
encodeURIComponent(id) +
|
||||
'" title="新标签打开期权实例(可划转)">打开</button>' +
|
||||
'<button type="button" class="btn btn-sm cond-inst-xfer" data-inst-id="' +
|
||||
escapeHtml(id) +
|
||||
'" title="' +
|
||||
escapeHtml(xferTitle) +
|
||||
'"' +
|
||||
(xferBlocked ? " disabled" : "") +
|
||||
">划入交易</button>" +
|
||||
'<button type="button" class="btn btn-secondary btn-sm cond-inst-open" data-inst-id="' +
|
||||
escapeHtml(id) +
|
||||
'" title="新标签打开实例">打开</button>' +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
@@ -324,8 +427,10 @@
|
||||
const sim = [];
|
||||
const live = [];
|
||||
const other = [];
|
||||
candidatesById = {};
|
||||
list.forEach(function (it) {
|
||||
const m = instanceMode(it);
|
||||
candidatesById[String(it.id)] = it;
|
||||
if (m === "sim") sim.push(it);
|
||||
else if (m === "live") live.push(it);
|
||||
else other.push(it);
|
||||
@@ -334,12 +439,18 @@
|
||||
renderCandidateGroup("sim", sim, checkedIds) +
|
||||
renderCandidateGroup("live", live, checkedIds) +
|
||||
renderCandidateGroup("", other, checkedIds);
|
||||
box.querySelectorAll(".cond-inst-xfer").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
transferFundingToTrading(btn.getAttribute("data-inst-id") || "");
|
||||
});
|
||||
});
|
||||
box.querySelectorAll(".cond-inst-open").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const iid = decodeURIComponent(btn.getAttribute("data-inst-id") || "");
|
||||
openInstanceTab(iid, "options");
|
||||
openInstanceTab(btn.getAttribute("data-inst-id") || "", "options");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user