feat(web-admin): generate contract DOCX blob from prepared HTML

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-09-05 14:42:44 +08:00
1 parent 17b42dc06c
commit b078245fbc
1 file changed
+28
@@ -1,5 +1,33 @@
/** 合同打印弹窗:HTML → DOCX 预处理与生成 */
import HTMLtoDOCX from '@turbodocx/html-to-docx'
const DOCX_MIME = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
/**
* 将已预处理的合同 HTML 转为 DOCX Blob(浏览器下载用)。
* 调用方须先执行 prepareContractHtmlForDocx。
*/
export async function generateContractDocxBlob(
preparedHtml: string,
title?: string
): Promise<Blob> {
const fullHtml = `<!DOCTYPE html><html><head><meta charset="UTF-8" /></head><body>${preparedHtml}</body></html>`
const result = await HTMLtoDOCX(fullHtml, null, {
orientation: 'portrait',
title: title || '合同',
margins: {
top: 720,
right: 720,
bottom: 720,
left: 720
}
})
if (result instanceof Blob) return result
return new Blob([result as ArrayBuffer], { type: DOCX_MIME })
}
export function parseContractSupplierCode(contractNo?: string | null): string {
if (!contractNo) return 'SX'
const match = String(contractNo).match(/^([A-Z]+)\/X-JT/)