总览:平仓按钮移到操作列,表格居中。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-02 16:07:23 +08:00
parent fb653c150c
commit 45464a6089
2 changed files with 52 additions and 30 deletions
+40 -23
View File
@@ -24,39 +24,19 @@
.replace(/"/g, "&quot;");
}
function positionSummary(brief, instanceId, online) {
function positionSummary(brief) {
const list = brief || [];
if (!list.length) return '<span class="muted">暂无持仓</span>';
const items = list.slice(0, 8).map(function (p) {
const id = p.inst_id || "";
const sheets = escapeHtml(String(p.sheets != null ? p.sheets : "—"));
const invalid = !!(p.bid_invalid || (p.bid_px == null && (p.bid_sz == null || p.bid_sz === "")));
const reason = (p.bid_invalid_reason || "买一无效,禁止平仓").toString();
let closeBtn = "";
if (online && id) {
if (invalid) {
closeBtn =
'<button type="button" class="btn btn-sm btn-danger" disabled title="' +
escapeHtml(reason) +
'">平仓</button>';
} else {
closeBtn =
'<button type="button" class="btn btn-sm btn-danger" data-close-inst="' +
encodeURIComponent(String(instanceId)) +
'" data-close-opt="' +
encodeURIComponent(id) +
'" title="买一限价全平">平仓</button>';
}
}
return (
"<li><span class=\"pos-brief-main\">" +
"<li>" +
escapeHtml(id) +
" · " +
sheets +
"张 · " +
fmtPnlHtml(p.pnl_usdt) +
"</span>" +
closeBtn +
"</li>"
);
});
@@ -67,6 +47,42 @@
return "<ul class=\"pos-brief\">" + items.join("") + more + "</ul>";
}
function closeActionButtons(brief, instanceId, online) {
if (!online) return "";
const list = (brief || []).filter(function (p) {
return !!(p && p.inst_id);
});
if (!list.length) return "";
return list
.slice(0, 8)
.map(function (p) {
const id = p.inst_id || "";
const invalid = !!(
p.bid_invalid ||
(p.bid_px == null && (p.bid_sz == null || p.bid_sz === ""))
);
const reason = (p.bid_invalid_reason || "买一无效,禁止平仓").toString();
const tip = list.length > 1 ? id + " · 买一限价全平" : "买一限价全平";
if (invalid) {
return (
'<button type="button" class="btn btn-danger" disabled title="' +
escapeHtml(reason) +
'">平仓</button>'
);
}
return (
'<button type="button" class="btn btn-danger" data-close-inst="' +
encodeURIComponent(String(instanceId)) +
'" data-close-opt="' +
encodeURIComponent(id) +
'" title="' +
escapeHtml(tip) +
'">平仓</button>'
);
})
.join("");
}
function fmtBidPx(v) {
if (v == null || v === "") return "—";
const n = Number(v);
@@ -148,7 +164,7 @@
fmtPnlHtml(pnl) +
"</td>" +
"<td>" +
positionSummary(brief, row.id, online) +
positionSummary(brief) +
"</td>" +
"<td>" +
bidLiquiditySummary(brief) +
@@ -163,6 +179,7 @@
'<button type="button" class="btn" data-open-tab="' +
encodeURIComponent(row.id) +
'">新标签</button>' +
closeActionButtons(brief, row.id, online) +
"</div></td>" +
"</tr>"
);