From b9f76f4d534ef24172e50b38638bebf3ca794362 Mon Sep 17 00:00:00 2001 From: dekun Date: Sun, 4 Oct 2026 18:14:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=8D=95=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=8B=BE=E9=80=89=E6=8C=89=20sim=20/=20live=20?= =?UTF-8?q?=E5=88=86=E7=BB=84=EF=BC=8C=E6=B2=A1=E6=9C=89=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=88=99=E4=B8=8D=E6=98=BE=E7=A4=BA=E8=AF=A5?= =?UTF-8?q?=E7=BB=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- app.py | 5 ++ static/cond_orders.js | 112 ++++++++++++++++++++++++++----------- static/hub.css | 2 + templates/base.html | 2 +- templates/cond_orders.html | 2 +- 5 files changed, 89 insertions(+), 34 deletions(-) diff --git a/app.py b/app.py index ce9e9b9..75452b9 100644 --- a/app.py +++ b/app.py @@ -635,6 +635,10 @@ def api_cond_order_candidates(): has_pos = isinstance(brief, list) and len(brief) > 0 locked = bool(snap.get("cond_order_locked")) selectable = bool(row.get("online")) and not has_pos and not locked + inst = snap.get("instance") if isinstance(snap.get("instance"), dict) else {} + mode = str(inst.get("mode") or "").strip().lower() + if mode not in ("sim", "live"): + mode = "" out.append( { "id": row.get("id"), @@ -643,6 +647,7 @@ def api_cond_order_candidates(): "has_position": has_pos, "cond_order_locked": locked, "selectable": selectable, + "mode": mode, "error": row.get("error") or "", } ) diff --git a/static/cond_orders.js b/static/cond_orders.js index 46b6ac4..702c068 100644 --- a/static/cond_orders.js +++ b/static/cond_orders.js @@ -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 ( + '" + ); + } + + function renderCandidateGroup(mode, items, checkedIds) { + if (!items.length) return ""; + const label = + mode === "sim" || mode === "live" + ? '
' + + mode + + "
" + : ""; + return ( + '
' + + label + + '
' + + items + .map(function (it) { + return renderCandidateCard(it, checkedIds); + }) + .join("") + + "
" + ); + } + 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 = '暂无启用实例'; return; } - box.innerHTML = list - .map(function (it) { - const disabled = !it.selectable; - const tip = disabled - ? it.has_position - ? "已有持仓" - : it.cond_order_locked - ? "条件单占用" - : it.online - ? "不可选" - : "离线" - : "可选"; - return ( - '" - ); - }) - .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() { diff --git a/static/hub.css b/static/hub.css index a119b8e..82c6460 100644 --- a/static/hub.css +++ b/static/hub.css @@ -1350,6 +1350,8 @@ input.readonly { min-height: 62px; } .cond-switch input { width: auto; margin: 0; } +.cond-inst-group + .cond-inst-group { margin-top: 14px; } +.cond-inst-group-label { margin-bottom: 8px; } .cond-inst-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); diff --git a/templates/base.html b/templates/base.html index 00bfced..4c97256 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,7 +4,7 @@ {% block title %}期权中控{% endblock %} - + {% if session.get('logged_in') %} diff --git a/templates/cond_orders.html b/templates/cond_orders.html index 7f392ff..f472f59 100644 --- a/templates/cond_orders.html +++ b/templates/cond_orders.html @@ -62,7 +62,7 @@
客户端
-
+