Skip to main content

预览模板 HTML

完全在内存中将任意 Smart Report 模板定义渲染为独立的 HTML 文档。预览渲染过程中不会创建或更新数据库记录,也不会启动 Chromium,从而为交互式模板编辑器、CI 校验检查及 AI 设计迭代保持极快的响应速度。

在无头与 AI 流水线中,可在通过 创建报告模板 或 更新报告模板 持久化模板之前,使用此端点对 sections、reportTheme、页边距以及核验评分设置(score、scoreProfile、scoreScale)进行迭代调试。如果在渲染带主题或带评分的模板时未在 sampleData 中提供 steps 或 results,渲染器会自动注入合成的司机示例数据,以确保预览完整呈现。

端点​

POST https://api.verifik.co/v2/smart-report-templates/preview-html

Smart-Agent 代理(https://ai.verifik.co)暴露了完全相同的 /v2/... 路径,并同样要求携带你自己的 Authorization: Bearer <VERIFIK_JWT> 请求头。

请求头​

名称值
Content-Typeapplication/json
Acceptapplication/json
AuthorizationBearer <VERIFIK_JWT>

请求体参数​

此端点接受预览/评分辅助字段以及所有公开的模板设计字段(sections、reportTheme、sampleData、margins、pageSize、orientation、pdfEngine、primaryColor、identityColor、pageBackgroundColor、logo、header、footer、legend、termsAndConditions、watermark、showPageNumbers、customFonts 等)。

名称类型必填说明
namestring否显示在预览页眉/元数据中的可选报告标题。
previewboolean否预览模式开关。默认为 true。
scoreboolean否启用核验评分计算并在响应中包含 verificationScore。
scoreProfilestring否来自 列出评分配置 的评分配置 ID。最多 64 个字符。
scoreScalestring否评分显示刻度:"unit" 或 "percent"。顶层预览辅助字段;持久化时请保存至 reportTheme.scoreScale。
themeTokensobject否自定义主题 Token 覆盖配置。顶层预览辅助字段;持久化时请保存至 reportTheme.tokens。
scoreSettingsobject否评分展示设置。顶层预览辅助字段;持久化时请保存至 reportTheme(scoreEnabled、scoreProfile)。
sectionsobject[]否要渲染的 ReportSection 区块数组。
reportThemestring / object否主题预设 ID("premium_dark"、"light_cards"、"editorial"、"dashboard")或完整的 reportTheme 配置对象。
sampleDataobject否核验示例负载(inputData、results、batchName、rowIndex)。在带主题或带评分的预览中若省略,将自动注入合成司机示例数据。
pageSizestring否"A4"、"Letter" 或 "Legal"。默认为 "A4"。
orientationstring否"portrait" 或 "landscape"。默认为 "portrait"。
marginsobject否页边距对象 `{ "top": 40, "right": 40, "bottom": 40, "left": 40 }`。

请求示例​

const fetch = require("node-fetch");

async function run() {
const res = await fetch(
"https://api.verifik.co/v2/smart-report-templates/preview-html",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${process.env.VERIFIK_JWT}`,
},
body: JSON.stringify({
name: "Driver Background Preview",
preview: true,
score: true,
scoreProfile: "cabify_driver",
scoreScale: "percent",
pageSize: "A4",
orientation: "portrait",
margins: { top: 40, right: 40, bottom: 40, left: 40 },
reportTheme: "light_cards",
sections: [
{
id: "sec-score",
type: "scoreGauge",
order: 0,
label: "Overall Score",
},
{
id: "sec-breakdown",
type: "categoryBreakdown",
order: 1,
label: "Category Breakdown",
},
],
}),
}
);

console.log(await res.json());
}

run();

响应示例​

{
"data": {
"html": "<!DOCTYPE html><html><head><meta charset=\"utf-8\" />...</head><body>...</body></html>",
"verificationScore": {
"profile": "cabify_driver",
"scale": "percent",
"score": 92
}
}
}

注意事项​

  • 仅当启用核验评分时(score: true 或在 reportTheme 中启用),data 中才会包含 verificationScore。
  • 由于此端点纯内存渲染、无数据库写入且不启动 Chromium,因此非常适合在调用 下载模板示例 进行最终 PDF 分页检查前用于快速排版迭代。
  • 当通过 创建报告模板 或 更新报告模板 持久化已预览的设计时,请将顶层预览辅助字段(scoreScale、themeTokens、scoreSettings)放入 reportTheme(reportTheme.scoreScale、reportTheme.tokens、reportTheme.scoreEnabled/reportTheme.scoreProfile)中。

相关页面​