From 69b917fa605be8ccd0984e5c095f24d6476dce95 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 05 六月 2026 00:55:46 +0800
Subject: [PATCH] 1

---
 src/views/officeProcessAutomation/ApproveManage/approve-shared/approvalTemplateBindingUtils.js |   91 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-shared/approvalTemplateBindingUtils.js b/src/views/officeProcessAutomation/ApproveManage/approve-shared/approvalTemplateBindingUtils.js
new file mode 100644
index 0000000..d68016f
--- /dev/null
+++ b/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锛坧rop 涓� 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;
+}

--
Gitblit v1.9.3