Add reusable HTML template export

- Add template export utilities for standard JSON packages and standalone HTML template packages.

- Make the top-level JSON export use the standard surclaw template package format so it can be imported again.

- Add an HTML template package export that embeds A4/print styling and template metadata for visual preview and round-trip import.

- Extend template import to accept both JSON and HTML template package files while keeping old raw template JSON compatible.

- Add tests for package creation, HTML round-trip import, legacy JSON import, and file name cleanup.

- Update template management, feature, progress, testing, and AGENTS documentation for the new export formats.
This commit is contained in:
2026-05-02 03:49:21 +08:00
parent d61ee4f83a
commit 5a4056d899
8 changed files with 235 additions and 40 deletions

View File

@@ -34,8 +34,8 @@
- 删除或批量删除模板。
- 保存当前模板内容。
- 打印模板预览。
- 单个导出批量导出 JSON。
- 从 JSON 模板包导入。
- 单个导出 JSON 模板包、HTML 模板包和 PDF 打印预览,批量导出 JSON。
- 从 JSON 模板包或 HTML 模板包导入。
新增、编辑、保存内容和删除模板会优先调用后端 `POST/PATCH/DELETE /api/templates`,后端会对模板 HTML 做白名单清洗;成功后同步 `localStorage.templates` 作为兼容缓存。只有本地回退开启时API 失败才允许写本地模板。
@@ -72,7 +72,7 @@
## 导入导出格式
单模板导出大致结构:
单模板 JSON 模板包大致结构:
```json
{
@@ -85,4 +85,8 @@
}
```
批量导出使用 `type: "surclaw_template_package_batch"`,包含 `templates` 数组。当前导入逻辑只接受单模板包。
HTML 模板包是一个可直接用浏览器打开的完整 HTML 文件,包含 A4 页面样式、打印样式和内嵌的 `surclaw_template_package` 元数据。它比 JSON 更适合保留“报告整体观感”,也可以重新导入系统恢复模板 HTML 和字段定义。
PDF 导出走浏览器打印,适合归档和人工查看,不适合再次导入编辑。
批量导出使用 `type: "surclaw_template_package_batch"`,包含 `templates` 数组。当前导入逻辑只接受单模板 JSON/HTML 包。