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:
1 parent
cba3b0cccd
commit
600adfb6d8
3 files changed
+113
-9
No files matched your search
@@ -39,7 +39,10 @@
|
||||
<tr v-for="(row, idx) in model.rows" :key="`r-${idx}`">
|
||||
<th>{{ row.label }}</th>
|
||||
<td>
|
||||
<template v-if="row.urls?.length">
|
||||
<template v-if="row.blocks?.length">
|
||||
<OaPrintRelatedTree :blocks="row.blocks" />
|
||||
</template>
|
||||
<template v-else-if="row.urls?.length">
|
||||
<div v-for="(u, ui) in row.urls" :key="ui" class="oa-print-url">{{ u }}</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
@@ -78,6 +81,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { OaPrintModel } from '@/utils/oa-approval-print'
|
||||
import OaPrintRelatedTree from '@/components/oa-approval/OaPrintRelatedTree.vue'
|
||||
|
||||
defineOptions({ name: 'OaApprovalPrintSheet' })
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<!-- 关联审批单打印树(递归,最多 3 层由组装器保证) -->
|
||||
<template>
|
||||
<div class="oa-print-related">
|
||||
<div
|
||||
v-for="(b, bi) in blocks"
|
||||
:key="`blk-${b.indexLabel}-${bi}`"
|
||||
class="oa-print-related__block"
|
||||
>
|
||||
<div class="oa-print-related__title">{{ b.indexLabel }}. {{ b.title }}</div>
|
||||
<div
|
||||
v-for="(line, li) in b.lines || []"
|
||||
:key="`ln-${bi}-${li}`"
|
||||
class="oa-print-related__line"
|
||||
>
|
||||
<span class="oa-print-related__k">{{ line.label }}</span>
|
||||
<span class="oa-print-related__v">{{ line.value }}</span>
|
||||
</div>
|
||||
<div v-if="b.children?.length" class="oa-print-related__children">
|
||||
<OaPrintRelatedTree :blocks="b.children" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { RelatedPrintBlock } from '@/utils/oa-approval-print-related'
|
||||
|
||||
defineOptions({ name: 'OaPrintRelatedTree' })
|
||||
|
||||
defineProps<{
|
||||
blocks: RelatedPrintBlock[]
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.oa-print-related__block {
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.oa-print-related__title {
|
||||
margin-bottom: 2px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.oa-print-related__line {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.oa-print-related__k {
|
||||
flex: 0 0 auto;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.oa-print-related__v {
|
||||
color: #334155;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.oa-print-related__children {
|
||||
margin: 4px 0 0 14px;
|
||||
padding-left: 8px;
|
||||
border-left: 2px solid #cbd5e1;
|
||||
}
|
||||
</style>
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user