1
yyb
15 小时以前 69b917fa605be8ccd0984e5c095f24d6476dce95
src/views/officeProcessAutomation/ApproveManage/approve-shared/approvalTemplateBindingUtils.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,91 @@
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;
}