第一期骨架:登录、实例登记、多机总览、内嵌/新标签打开。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
||||
:root {
|
||||
--bg: #0f1219;
|
||||
--panel: #171c27;
|
||||
--line: #2a3348;
|
||||
--text: #e8ecf5;
|
||||
--muted: #8b95ab;
|
||||
--accent: #6c5ce7;
|
||||
--ok: #3dd68c;
|
||||
--bad: #ff6b6b;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Segoe UI", system-ui, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
a { color: #9ec1ff; text-decoration: none; }
|
||||
.topbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
background: #12161f;
|
||||
}
|
||||
.topbar nav a { margin-left: 14px; color: var(--muted); }
|
||||
.topbar nav a.active { color: #fff; }
|
||||
.brand { font-weight: 700; }
|
||||
.main { padding: 16px; max-width: 1200px; margin: 0 auto; }
|
||||
.page-head { display: flex; align-items: center; gap: 12px; }
|
||||
.muted { color: var(--muted); font-size: 0.9rem; }
|
||||
.flash {
|
||||
background: #2a2140;
|
||||
border: 1px solid #5b4a8a;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.login-card {
|
||||
max-width: 360px;
|
||||
margin: 10vh auto;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
}
|
||||
.stack label, .form-grid label { display: block; margin: 8px 0; }
|
||||
input[type="text"], input[type="password"], input:not([type]) {
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--line);
|
||||
background: #0d1017;
|
||||
color: var(--text);
|
||||
}
|
||||
button, .btn {
|
||||
display: inline-block;
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
border: 0;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-danger { background: #8b3a3a; }
|
||||
.panel {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 14px;
|
||||
margin: 14px 0;
|
||||
}
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
gap: 10px;
|
||||
align-items: end;
|
||||
}
|
||||
.check { display: flex !important; align-items: center; gap: 8px; }
|
||||
.inst-row { margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 12px;
|
||||
}
|
||||
.card .status-on { color: var(--ok); }
|
||||
.card .status-off { color: var(--bad); }
|
||||
.card table { width: 100%; font-size: 0.8rem; border-collapse: collapse; }
|
||||
.card td, .card th { border-bottom: 1px solid var(--line); padding: 4px 2px; text-align: left; }
|
||||
.desk { display: grid; grid-template-columns: 200px 1fr; gap: 12px; min-height: 70vh; max-width: none; }
|
||||
.desk-side {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 10px;
|
||||
}
|
||||
.desk-list { list-style: none; padding: 0; margin: 0; }
|
||||
.desk-list li { margin: 6px 0; }
|
||||
.desk-list li.active a { color: #fff; font-weight: 600; }
|
||||
.desk-main { display: flex; flex-direction: column; min-height: 70vh; }
|
||||
.desk-toolbar {
|
||||
display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.desk-frame {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
min-height: 65vh;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: #000;
|
||||
}
|
||||
.empty { padding: 40px; color: var(--muted); }
|
||||
@media (max-width: 800px) {
|
||||
.desk { grid-template-columns: 1fr; }
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
(function (global) {
|
||||
function fmtPnl(v) {
|
||||
if (v == null || v === "") return "—";
|
||||
const n = Number(v);
|
||||
if (!Number.isFinite(n)) return "—";
|
||||
return (n > 0 ? "+" : "") + n.toFixed(2) + " U";
|
||||
}
|
||||
|
||||
function renderCard(row) {
|
||||
const snap = row.snapshot || {};
|
||||
const inst = snap.instance || {};
|
||||
const pnl = (snap.pnl && snap.pnl.unrealized_usdt != null)
|
||||
? snap.pnl.unrealized_usdt
|
||||
: snap.upl_total_usdc;
|
||||
const brief = snap.positions_brief || snap.positions || [];
|
||||
const online = !!row.online;
|
||||
const status = online
|
||||
? '<span class="status-on">在线</span>'
|
||||
: '<span class="status-off">离线</span>';
|
||||
const mode = inst.mode || "—";
|
||||
const err = row.error ? '<div class="muted">错误: ' + escapeHtml(row.error) + "</div>" : "";
|
||||
let rows = "";
|
||||
(brief || []).slice(0, 6).forEach(function (p) {
|
||||
rows +=
|
||||
"<tr><td>" +
|
||||
escapeHtml(p.inst_id || "") +
|
||||
"</td><td>" +
|
||||
escapeHtml(String(p.sheets != null ? p.sheets : "")) +
|
||||
"</td><td>" +
|
||||
escapeHtml(fmtPnl(p.pnl_usdt)) +
|
||||
"</td></tr>";
|
||||
});
|
||||
if (!rows) rows = '<tr><td colspan="3" class="muted">暂无持仓</td></tr>';
|
||||
return (
|
||||
'<article class="card">' +
|
||||
"<h3>" +
|
||||
escapeHtml(row.name || "") +
|
||||
"</h3>" +
|
||||
"<div>" +
|
||||
status +
|
||||
" · " +
|
||||
escapeHtml(mode) +
|
||||
" · 浮盈 " +
|
||||
escapeHtml(fmtPnl(pnl)) +
|
||||
"</div>" +
|
||||
'<div class="muted">拉取: ' +
|
||||
escapeHtml(row.pulled_at || "") +
|
||||
"</div>" +
|
||||
err +
|
||||
"<table><thead><tr><th>合约</th><th>张</th><th>盈亏</th></tr></thead><tbody>" +
|
||||
rows +
|
||||
"</tbody></table>" +
|
||||
'<p><a class="btn" href="/desk?id=' +
|
||||
encodeURIComponent(row.id) +
|
||||
'">内嵌打开</a> ' +
|
||||
'<button type="button" class="btn" data-open-tab="' +
|
||||
encodeURIComponent(row.id) +
|
||||
'">新标签</button></p>' +
|
||||
"</article>"
|
||||
);
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return String(s)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """);
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
const status = document.getElementById("overview-status");
|
||||
const grid = document.getElementById("overview-grid");
|
||||
if (!grid) return;
|
||||
if (status) status.textContent = "刷新中…";
|
||||
try {
|
||||
const r = await fetch("/api/overview");
|
||||
const d = await r.json();
|
||||
if (!d.ok) throw new Error(d.msg || "失败");
|
||||
const list = d.instances || [];
|
||||
if (!list.length) {
|
||||
grid.innerHTML = '<p class="muted">暂无启用实例,请先到「实例」添加.</p>';
|
||||
} else {
|
||||
grid.innerHTML = list.map(renderCard).join("");
|
||||
grid.querySelectorAll("[data-open-tab]").forEach(function (btn) {
|
||||
btn.addEventListener("click", async function () {
|
||||
const id = btn.getAttribute("data-open-tab");
|
||||
const rr = await fetch("/api/instances/" + id + "/open_url");
|
||||
const dd = await rr.json();
|
||||
if (dd.ok && dd.url) window.open(dd.url, "_blank", "noopener");
|
||||
else alert(dd.msg || "无法打开");
|
||||
});
|
||||
});
|
||||
}
|
||||
if (status) status.textContent = "已更新 · 共 " + list.length + " 台";
|
||||
} catch (e) {
|
||||
if (status) status.textContent = e.message || "加载失败";
|
||||
}
|
||||
}
|
||||
|
||||
function boot() {
|
||||
const btn = document.getElementById("btn-refresh");
|
||||
if (btn) btn.addEventListener("click", refresh);
|
||||
refresh();
|
||||
setInterval(refresh, 10000);
|
||||
}
|
||||
|
||||
global.HubOverview = { boot: boot, refresh: refresh };
|
||||
})(window);
|
||||
Reference in New Issue
Block a user