feat: MD-style popup print for strategy doc and checklist
Open clean white document in new tab with auto print dialog instead of printing the dark hub page. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -80,6 +80,7 @@ from lib.hub.hub_entry_plan_lib import (
|
||||
)
|
||||
from lib.hub.hub_strategy_lib import (
|
||||
build_export_html,
|
||||
build_print_html,
|
||||
load_strategy_payload,
|
||||
strategy_meta_payload,
|
||||
)
|
||||
@@ -2985,6 +2986,19 @@ def api_strategy_export(exchange_key: str):
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/strategy/{exchange_key}/print")
|
||||
def api_strategy_print(exchange_key: str, part: str = "doc"):
|
||||
key = exchange_key.strip().lower()
|
||||
p = (part or "doc").strip().lower()
|
||||
if p not in ("doc", "checklist"):
|
||||
return JSONResponse({"ok": False, "msg": "part must be doc or checklist"}, status_code=400)
|
||||
try:
|
||||
html = build_print_html(key, p)
|
||||
except KeyError:
|
||||
return JSONResponse({"ok": False, "msg": "unknown exchange or part"}, status_code=404)
|
||||
return HTMLResponse(content=html)
|
||||
|
||||
|
||||
@app.get("/api/entry-plans/meta")
|
||||
def api_entry_plans_meta():
|
||||
init_entry_plan_db()
|
||||
|
||||
@@ -7545,12 +7545,6 @@ body.funds-fullscreen-open {
|
||||
.strategy-col-head .strategy-col-title {
|
||||
margin: 0;
|
||||
}
|
||||
.strategy-col-title-print {
|
||||
display: none;
|
||||
margin: 0 0 14px;
|
||||
font-size: 0.95rem;
|
||||
color: var(--text-soft);
|
||||
}
|
||||
.strategy-col-print {
|
||||
flex-shrink: 0;
|
||||
padding: 4px 10px;
|
||||
@@ -7660,17 +7654,6 @@ body.funds-fullscreen-open {
|
||||
color: var(--muted);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.strategy-print-header {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.strategy-print-header.hidden {
|
||||
display: none;
|
||||
}
|
||||
.strategy-print-meta {
|
||||
margin: 4px 0 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.strategy-layout {
|
||||
@@ -7685,39 +7668,3 @@ body.funds-fullscreen-open {
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
body.hub-strategy-printing .app-bg,
|
||||
body.hub-strategy-printing .app-header,
|
||||
body.hub-strategy-printing .no-print,
|
||||
body.hub-strategy-printing .page:not(#page-strategy) {
|
||||
display: none !important;
|
||||
}
|
||||
body.hub-strategy-printing #page-strategy {
|
||||
display: block !important;
|
||||
}
|
||||
body.hub-strategy-printing .strategy-print-header {
|
||||
display: block !important;
|
||||
}
|
||||
body.hub-strategy-printing .strategy-col-title-print {
|
||||
display: block !important;
|
||||
}
|
||||
body.hub-strategy-printing .strategy-doc-body {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
body.hub-strategy-print-doc .strategy-checklist-card {
|
||||
display: none !important;
|
||||
}
|
||||
body.hub-strategy-print-checklist .strategy-doc-card {
|
||||
display: none !important;
|
||||
}
|
||||
body.hub-strategy-printing .strategy-layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
body.hub-strategy-printing .card {
|
||||
break-inside: avoid;
|
||||
box-shadow: none;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -868,26 +868,20 @@
|
||||
<span id="strategy-load-status" class="toolbar-meta"></span>
|
||||
</div>
|
||||
<div id="strategy-print-root" class="strategy-print-root">
|
||||
<div id="strategy-print-header" class="strategy-print-header hidden">
|
||||
<h2 id="strategy-print-title"></h2>
|
||||
<p id="strategy-print-meta" class="strategy-print-meta"></p>
|
||||
</div>
|
||||
<div class="strategy-layout">
|
||||
<section class="card strategy-doc-card">
|
||||
<div class="strategy-col-head no-print">
|
||||
<div class="strategy-col-head">
|
||||
<h3 class="strategy-col-title">策略说明</h3>
|
||||
<button type="button" id="strategy-btn-print-doc" class="ghost strategy-col-print">打印</button>
|
||||
</div>
|
||||
<h3 class="strategy-col-title strategy-col-title-print">策略说明</h3>
|
||||
<div id="strategy-doc-body" class="strategy-doc-body prose"></div>
|
||||
<p id="strategy-doc-source" class="strategy-doc-source"></p>
|
||||
</section>
|
||||
<section class="card strategy-checklist-card">
|
||||
<div class="strategy-col-head no-print">
|
||||
<div class="strategy-col-head">
|
||||
<h3 id="strategy-checklist-title" class="strategy-col-title">开仓检查清单</h3>
|
||||
<button type="button" id="strategy-btn-print-checklist" class="ghost strategy-col-print">打印</button>
|
||||
</div>
|
||||
<h3 id="strategy-checklist-title-print" class="strategy-col-title strategy-col-title-print">开仓检查清单</h3>
|
||||
<div id="strategy-checklist-body" class="strategy-checklist-body"></div>
|
||||
<ul id="strategy-checklist-footnotes" class="strategy-checklist-footnotes"></ul>
|
||||
</section>
|
||||
@@ -1160,7 +1154,7 @@
|
||||
<script src="/assets/archive.js?v=20260626-archive-layout"></script>
|
||||
<script src="/assets/funds.js?v=20260609-hub-funds-fold"></script>
|
||||
<script src="/assets/dashboard.js?v=20260612-dash-monitor-count"></script>
|
||||
<script src="/assets/strategy.js?v=2"></script>
|
||||
<script src="/assets/strategy.js?v=3"></script>
|
||||
<script src="/assets/ai_review_render.js?v=3"></script>
|
||||
<script src="/assets/time_close_ui.js?v=3"></script>
|
||||
<script src="/assets/backup.js?v=1"></script>
|
||||
|
||||
@@ -12,12 +12,8 @@
|
||||
const docCard = page.querySelector(".strategy-doc-card");
|
||||
const checklistCard = page.querySelector(".strategy-checklist-card");
|
||||
const checklistTitle = document.getElementById("strategy-checklist-title");
|
||||
const checklistTitlePrint = document.getElementById("strategy-checklist-title-print");
|
||||
const checklistBody = document.getElementById("strategy-checklist-body");
|
||||
const footnotesEl = document.getElementById("strategy-checklist-footnotes");
|
||||
const printTitle = document.getElementById("strategy-print-title");
|
||||
const printMeta = document.getElementById("strategy-print-meta");
|
||||
const printHeader = document.getElementById("strategy-print-header");
|
||||
const btnPrintDoc = document.getElementById("strategy-btn-print-doc");
|
||||
const btnPrintChecklist = document.getElementById("strategy-btn-print-checklist");
|
||||
const btnDownload = document.getElementById("strategy-btn-download");
|
||||
@@ -87,7 +83,6 @@
|
||||
const cl = checklist || {};
|
||||
const title = cl.title || "开仓检查清单";
|
||||
if (checklistTitle) checklistTitle.textContent = title;
|
||||
if (checklistTitlePrint) checklistTitlePrint.textContent = title;
|
||||
if (!checklistBody) return;
|
||||
const groups = cl.groups || [];
|
||||
if (!groups.length) {
|
||||
@@ -117,12 +112,6 @@
|
||||
docSource.textContent = `文档:${data.md_source || ""}${ver}`;
|
||||
}
|
||||
renderChecklist(data.checklist);
|
||||
if (printTitle) printTitle.textContent = data.title || data.label || "";
|
||||
if (printMeta) {
|
||||
const ver = data.version ? ` · ${data.version}` : "";
|
||||
printMeta.textContent = `${data.label || activeKey}${ver}`;
|
||||
}
|
||||
if (printHeader) printHeader.classList.remove("hidden");
|
||||
scheduleHeightSync();
|
||||
}
|
||||
|
||||
@@ -154,22 +143,12 @@
|
||||
}
|
||||
|
||||
function printSection(mode) {
|
||||
document.body.classList.remove("hub-strategy-print-doc", "hub-strategy-print-checklist");
|
||||
document.body.classList.add("hub-strategy-printing");
|
||||
if (mode === "doc") document.body.classList.add("hub-strategy-print-doc");
|
||||
if (mode === "checklist") document.body.classList.add("hub-strategy-print-checklist");
|
||||
window.print();
|
||||
window.addEventListener(
|
||||
"afterprint",
|
||||
() => {
|
||||
document.body.classList.remove(
|
||||
"hub-strategy-printing",
|
||||
"hub-strategy-print-doc",
|
||||
"hub-strategy-print-checklist"
|
||||
);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
const part = mode === "checklist" ? "checklist" : "doc";
|
||||
const url = `/api/strategy/${encodeURIComponent(activeKey)}/print?part=${encodeURIComponent(part)}`;
|
||||
const w = window.open(url, "_blank", "noopener,noreferrer");
|
||||
if (!w) {
|
||||
if (statusEl) statusEl.textContent = "请允许弹出窗口以打开打印预览";
|
||||
}
|
||||
}
|
||||
|
||||
function bindActions() {
|
||||
|
||||
Reference in New Issue
Block a user