feat(sign): 支持多位置签名并优化坐标识别与模板版本校验
This commit is contained in:
@@ -137,27 +137,21 @@ export function readVersionContentHtml(dto: TemplateVersionResponseDto | null):
|
||||
* 把正文 HTML 里的占位符编译成后端可留存的结构化字段定义。
|
||||
*
|
||||
* 正文填写项和 PDF 签名几何是两个独立契约:formFields 负责字段语义,
|
||||
* signatureFields 只负责患者签名图在服务端生成 PDF 中的位置。
|
||||
* signatureFields 负责各签名图在服务端生成 PDF 中的位置。
|
||||
*/
|
||||
export function buildSignatureFieldsPayload(contentHtml: string): unknown[] {
|
||||
const field = collectFieldDefs(contentHtml).find((item) => item.id === 'signature')
|
||||
if (!field || field.kind !== 'signature') {
|
||||
throw new Error('请在正文中插入“患者签名”占位符')
|
||||
}
|
||||
if (!field.pdfPosition) {
|
||||
throw new Error('请先为“患者签名”配置 PDF 页码和签名位置')
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: field.id,
|
||||
page: field.pdfPosition.page,
|
||||
x: field.pdfPosition.x,
|
||||
y: field.pdfPosition.y,
|
||||
width: field.pdfPosition.width,
|
||||
height: field.pdfPosition.height,
|
||||
coordinateSystem: field.pdfPosition.coordinateSystem,
|
||||
},
|
||||
]
|
||||
const fields = collectFieldDefs(contentHtml).filter((field) => field.kind === 'signature')
|
||||
if (!fields.length) throw new Error('请在正文中插入签名占位符')
|
||||
const document = new DOMParser().parseFromString(contentHtml, 'text/html')
|
||||
const ids = Array.from(document.querySelectorAll('[data-kind="signature"][data-field]')).map(
|
||||
(node) => node.getAttribute('data-field'),
|
||||
)
|
||||
if (new Set(ids).size !== ids.length)
|
||||
throw new Error('签名占位符标识重复,请删除重复位置后重新插入')
|
||||
return fields.map((field) => {
|
||||
if (!field.pdfPosition) throw new Error(`请先为“${field.label}”配置 PDF 签名位置`)
|
||||
return { id: field.id, ...field.pdfPosition }
|
||||
})
|
||||
}
|
||||
|
||||
export function buildFormFieldsPayload(contentHtml: string): unknown[] {
|
||||
|
||||
Reference in New Issue
Block a user