import { mapAttachmentsFromApi, mapTemplateFromApi, unwrapTemplateDetail, } from "../approve-template/approveTemplateConstants.js"; import { buildSubmitTemplateFromRow } from "../approve-template/formConfigUtils.js"; import { createEmptySubmitForm, validateSubmitFlowNodes, } from "../approve-list/approveListConstants.js"; export function attachmentDisplayName(file) { return ( file?.fileName || file?.originalFilename || file?.name || file?.blobName || "附件" ); } /** 接口详情 → 提交绑定快照(含流程、附件、填报项) */ export function buildTemplateBindingFromDetail(detailRow) { const mapped = mapTemplateFromApi(unwrapTemplateDetail(detailRow)); const templateAttachments = mapAttachmentsFromApi(mapped); const tpl = { ...buildSubmitTemplateFromRow(mapped), templateId: mapped.id, businessType: mapped.businessType, storageBlobDTOs: templateAttachments, }; const base = createEmptySubmitForm(String(mapped.id ?? ""), tpl, mapped.flowNodes); return { templateId: mapped.id, templateName: mapped.templateName || tpl.label || "", businessType: mapped.businessType ?? "", templateSnapshot: tpl, formFieldDefs: tpl.fields || [], formPayload: base.formPayload, flowNodes: base.flowNodes, templateAttachments: JSON.parse(JSON.stringify(templateAttachments)), storageBlobDTOs: [], }; } /** 根据模板 fields 生成 el-form rules(prop 为 formPayload.xxx) */ export function buildFormPayloadRules(fields = []) { const rules = {}; (fields || []).forEach((f) => { if (!f.required || !f.key) return; const prop = `formPayload.${f.key}`; if (f.type === "number") { rules[prop] = [{ required: true, message: `请填写${f.label}`, trigger: "blur" }]; } else if (f.type === "datetimerange" || f.type === "date" || f.type === "select") { rules[prop] = [{ required: true, message: `请选择${f.label}`, trigger: "change" }]; } else { rules[prop] = [{ required: true, message: `请填写${f.label}`, trigger: "blur" }]; } }); return rules; } /** 校验模板绑定:审批流程(附件选填,由用户自行上传) */ export function validateTemplateBinding({ flowNodes }) { const flowCheck = validateSubmitFlowNodes(flowNodes); if (!flowCheck.ok) return flowCheck; return { ok: true, nodes: flowCheck.nodes }; } /** 合并绑定结果到业务表单对象(字段名可按业务覆盖) */ export function applyBindingToForm(target, binding, fieldMap = {}) { if (!target || !binding) return target; const map = { templateId: "templateId", templateName: "templateName", businessType: "businessType", templateSnapshot: "templateSnapshot", formFieldDefs: "formFieldDefs", formPayload: "formPayload", flowNodes: "flowNodes", templateAttachments: "templateAttachments", storageBlobDTOs: "storageBlobDTOs", ...fieldMap, }; Object.entries(map).forEach(([srcKey, destKey]) => { if (binding[srcKey] !== undefined) { target[destKey] = binding[srcKey]; } }); return target; }