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:
@@ -1374,7 +1374,7 @@
|
||||
<script src="/assets/quotes.js?v=20260717-quotes-feed"></script>
|
||||
<script src="/assets/funds.js?v=20260717-funds-scroll-fix"></script>
|
||||
<script src="/assets/dashboard.js?v=20260717-dash-kpi-merge"></script>
|
||||
<script src="/assets/strategy.js?v=3"></script>
|
||||
<script src="/assets/strategy.js?v=4"></script>
|
||||
<script src="/assets/help.js?v=1"></script>
|
||||
<script src="/assets/logs.js?v=1"></script>
|
||||
<script src="/assets/ai_review_render.js?v=3"></script>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user