feat(web-admin): print relatedApproval as recursive multi-line blocks

PDF export fetches summaries and renders up to three nested levels with
dedupe, instead of dumping raw instance ids.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-07-22 23:04:06 +08:00
1 parent cba3b0cccd
commit 600adfb6d8
3 files changed
+113 -9

No files matched your search

+41 -8
View File
@@ -1,21 +1,31 @@
/**
* OA 审批单钉钉风格 PDF 导出
* Spec: docs/superpowers/specs/2026-07-15-oa-approval-print-pdf-design.md
* Nested related: docs/superpowers/specs/2026-07-22-oa-related-approval-nested-print-design.md
*/
import { createApp, h, nextTick } from 'vue'
import html2canvas from 'html2canvas'
import { jsPDF } from 'jspdf'
import {
assembleRelatedPrintBlocks,
normalizeRelatedIdsFromFormValue,
type RelatedPrintBlock
} from '@/utils/oa-approval-print-related'
export const OA_PRINT_COMPANY_NAME = '安徽中科兴皖医学研究有限公司'
export type OaStampClass = 'ok' | 'run' | 'rej' | 'ret' | 'can'
export type { RelatedPrintBlock }
export type OaPrintFieldRow = {
label: string
/** 普通文本(可含换行) */
text?: string
/** 附件 / 链接列表 */
urls?: string[]
/** 关联审批单多行块(优先于 text) */
blocks?: RelatedPrintBlock[]
}
export type OaPrintFlowItem = {
@@ -167,20 +177,41 @@ function formatScalar(value: unknown): string {
return String(value)
}
function walkRules(rules: any[], formData: Record<string, any>, out: OaPrintFieldRow[]) {
async function walkRules(
rules: any[],
formData: Record<string, any>,
out: OaPrintFieldRow[]
) {
if (!Array.isArray(rules)) return
for (const rule of rules) {
if (!rule || typeof rule !== 'object') continue
const type = String(rule.type || '').trim()
const children = rule.children || rule.props?.rule
if (Array.isArray(children) && children.length) {
walkRules(children, formData, out)
await walkRules(children, formData, out)
}
if (SKIP_RULE_TYPES.has(type)) continue
const field = String(rule.field || '').trim()
if (!field) continue
const label = String(rule.title || rule.label || rule.props?.label || field).trim() || field
const value = formData?.[field]
if (type === 'relatedApproval') {
const ids = normalizeRelatedIdsFromFormValue(value)
if (!ids.length) {
out.push({ label, text: '-' })
continue
}
const blocks = await assembleRelatedPrintBlocks(ids)
out.push({
label,
blocks: blocks.length
? blocks
: [{ indexLabel: '1', title: '关联信息加载失败' }]
})
continue
}
if (UPLOAD_TYPES.has(type) || String(rule.name || '').toLowerCase().includes('upload')) {
const urls = extractUrls(value)
out.push({ label, urls: urls.length ? urls : [], text: urls.length ? undefined : '-' })
@@ -203,7 +234,7 @@ function walkRules(rules: any[], formData: Record<string, any>, out: OaPrintFiel
}
}
function buildFormRows(detail: any): OaPrintFieldRow[] {
async function buildFormRows(detail: any): Promise<OaPrintFieldRow[]> {
const schema = detail?.formSchemaJson
const formData = (detail?.formDataJson || {}) as Record<string, any>
const rule = Array.isArray(schema?.rule)
@@ -212,7 +243,7 @@ function buildFormRows(detail: any): OaPrintFieldRow[] {
? schema
: []
const out: OaPrintFieldRow[] = []
walkRules(rule, formData, out)
await walkRules(rule, formData, out)
if (out.length) return out
// schema 缺失:兜底平铺 formData
for (const [k, v] of Object.entries(formData)) {
@@ -313,10 +344,10 @@ function buildFlowItems(detail: any): OaPrintFlowItem[] {
return items
}
export function buildOaPrintModel(
export async function buildOaPrintModel(
detail: any,
opts: { printerName: string; printTime?: string }
): OaPrintModel {
): Promise<OaPrintModel> {
const { stampClass, stampText } = resolveStamp(detail?.status)
const appName = String(detail?.appName || '').trim()
const titleFallback = String(detail?.title || '').trim()
@@ -337,13 +368,15 @@ export function buildOaPrintModel(
}
]
const formRows = await buildFormRows(detail)
return {
title,
companyName: OA_PRINT_COMPANY_NAME,
createDate: formatDateOnly(detail?.createTime),
stampClass,
stampText,
rows: [...headerRows, ...buildFormRows(detail)],
rows: [...headerRows, ...formRows],
flowItems: buildFlowItems(detail),
printTime,
printerName,
@@ -402,7 +435,7 @@ export async function exportOaApprovalPdf(
detail: any,
opts: { printerName: string }
): Promise<void> {
const model = buildOaPrintModel(detail, { printerName: opts.printerName })
const model = await buildOaPrintModel(detail, { printerName: opts.printerName })
const filename = buildOaPrintFilename(detail)
const { default: OaApprovalPrintSheet } = await import(
'@/components/oa-approval/OaApprovalPrintSheet.vue'