条件单客户端勾选按 sim / live 分组,没有对应模式则不显示该组。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+80
-32
@@ -53,9 +53,76 @@
|
||||
return "st-done";
|
||||
}
|
||||
|
||||
function instanceMode(it) {
|
||||
const m = String((it && it.mode) || "").toLowerCase();
|
||||
return m === "sim" || m === "live" ? m : "";
|
||||
}
|
||||
|
||||
function renderCandidateCard(it, checkedIds) {
|
||||
const disabled = !it.selectable;
|
||||
const tip = disabled
|
||||
? it.has_position
|
||||
? "已有持仓"
|
||||
: it.cond_order_locked
|
||||
? "条件单占用"
|
||||
: it.online
|
||||
? "不可选"
|
||||
: "离线"
|
||||
: "可选";
|
||||
const id = String(it.id);
|
||||
const checked = !disabled && checkedIds.indexOf(id) >= 0;
|
||||
return (
|
||||
'<label class="cond-inst' +
|
||||
(disabled ? " is-off" : "") +
|
||||
'" title="' +
|
||||
escapeHtml(tip) +
|
||||
'">' +
|
||||
'<input type="checkbox" name="cf-inst" value="' +
|
||||
encodeURIComponent(id) +
|
||||
'"' +
|
||||
(disabled ? " disabled" : "") +
|
||||
(checked ? " checked" : "") +
|
||||
">" +
|
||||
'<span class="cond-inst-name">' +
|
||||
escapeHtml(it.name || "") +
|
||||
"</span>" +
|
||||
'<span class="cond-inst-tag">' +
|
||||
escapeHtml(tip) +
|
||||
"</span></label>"
|
||||
);
|
||||
}
|
||||
|
||||
function renderCandidateGroup(mode, items, checkedIds) {
|
||||
if (!items.length) return "";
|
||||
const label =
|
||||
mode === "sim" || mode === "live"
|
||||
? '<div class="cond-inst-group-label"><span class="overview-mode-tag overview-mode-tag--' +
|
||||
mode +
|
||||
'">' +
|
||||
mode +
|
||||
"</span></div>"
|
||||
: "";
|
||||
return (
|
||||
'<div class="cond-inst-group">' +
|
||||
label +
|
||||
'<div class="cond-inst-grid">' +
|
||||
items
|
||||
.map(function (it) {
|
||||
return renderCandidateCard(it, checkedIds);
|
||||
})
|
||||
.join("") +
|
||||
"</div></div>"
|
||||
);
|
||||
}
|
||||
|
||||
async function loadCandidates() {
|
||||
const box = document.getElementById("cf-instances");
|
||||
if (!box) return;
|
||||
const checkedIds = Array.prototype.slice
|
||||
.call(box.querySelectorAll('input[name="cf-inst"]:checked'))
|
||||
.map(function (el) {
|
||||
return decodeURIComponent(el.value || "");
|
||||
});
|
||||
const r = await fetch("/api/cond_orders/candidates");
|
||||
const d = await r.json();
|
||||
const list = d.instances || [];
|
||||
@@ -63,38 +130,19 @@
|
||||
box.innerHTML = '<span class="muted">暂无启用实例</span>';
|
||||
return;
|
||||
}
|
||||
box.innerHTML = list
|
||||
.map(function (it) {
|
||||
const disabled = !it.selectable;
|
||||
const tip = disabled
|
||||
? it.has_position
|
||||
? "已有持仓"
|
||||
: it.cond_order_locked
|
||||
? "条件单占用"
|
||||
: it.online
|
||||
? "不可选"
|
||||
: "离线"
|
||||
: "可选";
|
||||
return (
|
||||
'<label class="cond-inst' +
|
||||
(disabled ? " is-off" : "") +
|
||||
'" title="' +
|
||||
escapeHtml(tip) +
|
||||
'">' +
|
||||
'<input type="checkbox" name="cf-inst" value="' +
|
||||
encodeURIComponent(String(it.id)) +
|
||||
'"' +
|
||||
(disabled ? " disabled" : "") +
|
||||
">" +
|
||||
'<span class="cond-inst-name">' +
|
||||
escapeHtml(it.name || "") +
|
||||
"</span>" +
|
||||
'<span class="cond-inst-tag">' +
|
||||
escapeHtml(tip) +
|
||||
"</span></label>"
|
||||
);
|
||||
})
|
||||
.join("");
|
||||
const sim = [];
|
||||
const live = [];
|
||||
const other = [];
|
||||
list.forEach(function (it) {
|
||||
const m = instanceMode(it);
|
||||
if (m === "sim") sim.push(it);
|
||||
else if (m === "live") live.push(it);
|
||||
else other.push(it);
|
||||
});
|
||||
box.innerHTML =
|
||||
renderCandidateGroup("sim", sim, checkedIds) +
|
||||
renderCandidateGroup("live", live, checkedIds) +
|
||||
renderCandidateGroup("", other, checkedIds);
|
||||
}
|
||||
|
||||
async function loadOrders() {
|
||||
|
||||
Reference in New Issue
Block a user