Fix strategy checklist print closing too early.

Stop auto-closing the print tab on afterprint (short checklist pages were especially fragile), load print HTML via fetch into a blank window, and use CSS checkboxes instead of Unicode ballot boxes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-18 16:16:34 +08:00
parent faf21da955
commit 778a215ad7
4 changed files with 77 additions and 23 deletions
+31 -2
View File
@@ -142,12 +142,41 @@
renderTabs();
}
function printSection(mode) {
async function printSection(mode) {
const part = mode === "checklist" ? "checklist" : "doc";
const url = `/api/strategy/${encodeURIComponent(activeKey)}/print?part=${encodeURIComponent(part)}`;
const w = window.open(url, "_blank", "noopener,noreferrer");
// 同步打开空白页保留用户手势;再 fetch 写入,避免 noopener 丢句柄 / 短页误关窗
const w = window.open("about:blank", "_blank");
if (!w) {
if (statusEl) statusEl.textContent = "请允许弹出窗口以打开打印预览";
return;
}
try {
w.document.write(
"<!DOCTYPE html><title>打印准备中…</title><body style=\"font-family:sans-serif;padding:24px;color:#222\">正在加载打印内容…</body>"
);
w.document.close();
} catch (_) {}
try {
const r = await fetch(url, { credentials: "same-origin" });
const html = await r.text();
if (!r.ok) {
throw new Error((html && html.slice(0, 120)) || r.statusText || "加载打印页失败");
}
w.document.open();
w.document.write(html);
w.document.close();
if (statusEl) statusEl.textContent = "";
} catch (e) {
const msg = String(e && e.message ? e.message : e);
try {
w.document.open();
w.document.write(
`<!DOCTYPE html><body style="font-family:sans-serif;padding:24px;color:#222">打印页加载失败: ${esc(msg)}</body>`
);
w.document.close();
} catch (_) {}
if (statusEl) statusEl.textContent = msg;
}
}