| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | } |