Repository navigation
feat(export): 战局与问卷支持 PDF 导出,移除页面打印按钮 - #92
Merged
Merged
Conversation
原来的「打印 / 导出 PDF」只是 window.print(),打出来是带侧栏和按钮的后台页面, 既不能当数据导出,也不适合直接交给评审。改为在已有导出上补 PDF: - 新增 GET /api/battles/export.pdf:战局清单,状态/难度/裁决中文化, 超过 500 场时页首标注总数,避免误读为全量。 - 新增 GET /api/survey/export.pdf,支持 ?part=summary|detail 分别导出 汇总(结论、KPI、分布条形、原话摘录)与明细(逐份记录)。 - 后端排版用 reportlab;中文字体按 AGENT_PDF_FONT → 系统常见字体探测, 缺失时返回 503 并给出可执行提示,不产出乱码文件。 - 后台导出区改为 5 个按钮:战局 CSV / 战局 PDF / 问卷 CSV / 问卷汇总 PDF / 问卷明细 PDF;删除打印按钮,print.css 仅服务浏览器 Ctrl+P。 - CI 安装 fonts-noto-cjk,让 PDF 渲染用例在 Linux 上真正执行;本机无字体时跳过。 测试:后端 349 passed / 5 skipped(新增 11 条),前端 219 Vitest 通过, lint 8 warnings 0 error(与改动前一致),npm run build 通过。
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://feat-pdf-export-agent-attack-lab.3498414260.workers.dev (commit 0d7e693)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
_FONT_CANDIDATES 里 Windows 条目是 (path, subfont) 元组,Linux/macOS 条目 却写成了裸字符串,_register 的 `for path, subfont in candidates` 在遍历到 字符串时抛 ValueError: too many values to unpack。Windows 本机因为第一条 msyh.ttc 就命中并提前返回,问题从未暴露;CI(ubuntu + fonts-noto-cjk) 才复现,7 条 PDF 用例全部 error。 - 候选表统一为 (path, subfontIndex) 元组; - _register 增加归一化,兼容裸 path 写法,避免同类写错再次整体崩; - 验证:只留不存在的路径时返回 False → 上层抛 PdfFontUnavailable(503/skip)。
Deploying agent-attack-lab with
|
| Latest commit: |
0d7e693
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b6132d8d.agent-attack-lab.pages.dev |
| Branch Preview URL: | https://feat-pdf-export.agent-attack-lab.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
后台原来的「打印 / 导出 PDF」只是
window.print(),打出来是带侧栏、按钮、深色底的后台页面:既不是数据导出,也不能直接交给评审。这次在已有导出上补 PDF,并去掉这个语义混淆的按钮。改动
后端
GET /api/battles/export.pdf:战局清单,状态 / 难度 / 裁决中文化;最多 500 场,超量时页首标注总数(避免误读为全量)。GET /api/survey/export.pdf,支持?part=summary|detail:分别导出汇总(结论、KPI、分题分布、原话摘录)与明细(逐份记录)。默认all为完整报告。reportlab,中文按AGENT_PDF_FONT→ 系统常见字体探测;取不到字体返回 503 并给出可执行提示,不产出乱码文件。read_auth_dependency,问卷走check_browser_or_api_auth。前端
print.css保留,仅服务浏览器 Ctrl+P(隐藏侧栏/按钮、A4、表头重复、行不跨页)。CI
fonts-noto-cjk安装步骤 —— 否则 ubuntu 上 PDF 渲染用例必然失败。测试内另有 skip 兜底。验证
349 passed, 5 skipped,新增 11 条(鉴权 / 空数据 / PDF 魔数与 EOF / 会话鉴权 / 统计口径 / 拆分 / 非法 part 422 / 截断标注)219 passed(新增 1 条战局 PDF),Node 脚本测试 7 passedruff check与ruff format --check通过;oxlint8 warnings 0 error(与改动前一致)npm run build通过PDF 版式已逐页渲染核对:页脚按文档标题区分、并列数据不写成"以 X 为主"、明细表列宽合计 ≤ A4 可用宽度、长角色名换行不越列、表格不出现孤行。
注意
不含数据库结构变更,不改任何现有接口的返回结构与鉴权行为。