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:
dekun
2026-07-06 03:28:44 +08:00
parent 0d5b20c0db
commit 22b2db34fc
6 changed files with 245 additions and 105 deletions
+6 -27
View File
@@ -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() {