From 32aa9fc039cfd0065ec7c3726960e200dab3e92a Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 13 十月 2026 14:09:17 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_pro_山西长治' into dev_pro_山西长治

---
 src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js |  145 ++++++++++++++++++++++++++++--------------------
 1 files changed, 85 insertions(+), 60 deletions(-)

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
index 8489e13..df25e2e 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
@@ -2,48 +2,51 @@
   addApprovalTemplate,
   deleteApprovalTemplate,
   getApprovalTemplateDetail,
-  listApprovalTemplate,
   listApprovalTemplatePage,
   TEMPLATE_TYPE_BUILTIN,
-  TEMPLATE_TYPE_CUSTOM,
-  TEMPLATE_TYPE_OPTIONS,
   updateApprovalTemplate,
 } from "@/api/officeProcessAutomation/approvalTemplate.js";
 import { Search } from "@element-plus/icons-vue";
 import { ElMessage, ElMessageBox } from "element-plus";
-import { reactive, ref } from "vue";
+import { computed, reactive, ref } from "vue";
 import {
   buildApprovalTemplateListParams,
   createEmptyTemplateForm,
+  fetchBusinessTypeOptions,
   flowNodesSummary,
-  mapBuiltinCardFromApi,
+  isBuiltinTemplate,
   mapTemplateFromApi,
   mapTemplateToApi,
+  nodeDisplayName,
   nodeSignModeLabel,
-  templateTypeLabel,
-  unwrapTemplateList,
   formatDisplayTime,
   unwrapTemplateDetail,
   validateTemplateForm,
 } from "./approveTemplateConstants.js";
 import { parseFormConfigToData } from "./formConfigUtils.js";
 
-const LEGACY_STORAGE_KEY = "oa_approve_template_custom_v1";
+const FALLBACK_TEMPLATE_TYPE_OPTIONS = [
+  { value: 0, label: "绯荤粺鍐呯疆" },
+  { value: 1, label: "鑷畾涔�" },
+];
 
-function clearLegacyStorage() {
-  try {
-    localStorage.removeItem(LEGACY_STORAGE_KEY);
-  } catch {
-    /* ignore */
-  }
+function matchTemplateTypeValue(options, type) {
+  if (type == null || type === "") return false;
+  return options.some(
+    (x) => x.value === type || x.value === Number(type) || String(x.value) === String(type)
+  );
 }
 
 export function useApproveTemplate() {
-  clearLegacyStorage();
+  const templateTypeOptions = ref([...FALLBACK_TEMPLATE_TYPE_OPTIONS]);
 
-  const activeTab = ref("custom");
-  const builtinTemplates = ref([]);
-  const builtinLoading = ref(false);
+  function templateTypeLabel(type) {
+    if (type == null || type === "") return "鈥�";
+    const hit = templateTypeOptions.value.find(
+      (x) => x.value === type || x.value === Number(type) || String(x.value) === String(type)
+    );
+    return hit?.label || "鈥�";
+  }
 
   const searchForm = reactive({
     keyword: "",
@@ -58,20 +61,36 @@
   const form = reactive(createEmptyTemplateForm());
   const formRef = ref();
 
+  const isEditingBuiltin = computed(
+    () => formDialog.mode === "edit" && Number(form.templateType) === TEMPLATE_TYPE_BUILTIN
+  );
+
+  async function loadTemplateTypeOptions() {
+    try {
+      const list = await fetchBusinessTypeOptions();
+      templateTypeOptions.value = list.length ? list : [...FALLBACK_TEMPLATE_TYPE_OPTIONS];
+    } catch {
+      templateTypeOptions.value = [...FALLBACK_TEMPLATE_TYPE_OPTIONS];
+    }
+    if (!matchTemplateTypeValue(templateTypeOptions.value, form.businessType)) {
+      form.businessType = templateTypeOptions.value[0]?.value ?? "";
+    }
+  }
+
   const detailDialog = reactive({ visible: false });
   const detailRow = ref({});
   const detailLoading = ref(false);
 
   const formRules = {
     templateName: [{ required: true, message: "璇疯緭鍏ユā鏉垮悕绉�", trigger: "blur" }],
-    templateType: [{ required: true, message: "璇烽�夋嫨妯℃澘绫诲瀷", trigger: "change" }],
+    businessType: [{ required: true, message: "璇烽�夋嫨妯℃澘绫诲瀷", trigger: "change" }],
   };
 
   const tableColumn = ref([
     { label: "妯℃澘鍚嶇О", prop: "templateName", minWidth: 140 },
     {
       label: "妯℃澘绫诲瀷",
-      prop: "templateType",
+      prop: "businessType",
       width: 100,
       align: "center",
       formatData: (v) => templateTypeLabel(v),
@@ -86,10 +105,9 @@
     },
     {
       label: "娴佺▼姒傝",
-      prop: "flowNodes",
+      prop: "flowSummary",
       minWidth: 220,
       showOverflowTooltip: true,
-      formatData: (v) => flowNodesSummary(v),
     },
     {
       label: "鐘舵��",
@@ -107,13 +125,13 @@
       showOverflowTooltip: true,
       formatData: (v) => formatDisplayTime(v),
     },
-    {
-      label: "鏇存柊鏃堕棿",
-      prop: "updatedTime",
-      width: 170,
-      showOverflowTooltip: true,
-      formatData: (v) => formatDisplayTime(v),
-    },
+    // {
+    //   label: "鏇存柊鏃堕棿",
+    //   prop: "updatedTime",
+    //   width: 170,
+    //   showOverflowTooltip: true,
+    //   formatData: (v) => formatDisplayTime(v),
+    // },
     {
       dataType: "action",
       label: "鎿嶄綔",
@@ -127,24 +145,12 @@
           name: "鍒犻櫎",
           type: "danger",
           link: true,
+          disabled: (row) => isBuiltinTemplate(row),
           clickFun: (row) => removeTemplate(row),
         },
       ],
     },
   ]);
-
-  async function loadBuiltinTemplates() {
-    builtinLoading.value = true;
-    try {
-      const res = await listApprovalTemplate(TEMPLATE_TYPE_BUILTIN);
-      builtinTemplates.value = unwrapTemplateList(res).map(mapBuiltinCardFromApi);
-    } catch {
-      builtinTemplates.value = [];
-      ElMessage.warning("绯荤粺甯哥敤瀹℃壒鍔犺浇澶辫触");
-    } finally {
-      builtinLoading.value = false;
-    }
-  }
 
   async function fetchTemplateList() {
     tableLoading.value = true;
@@ -153,7 +159,11 @@
         buildApprovalTemplateListParams({ page, searchForm })
       );
       const data = res?.data || {};
-      tableData.value = (data.records || []).map(mapTemplateFromApi);
+      // 娴佺▼姒傝鎸夈�屽鎵圭被鍨嬄峰眰绾с�嶅睍绀猴紝闇�瑕佹妸妯℃澘鍚嶅甫杩涙枃妗堥噷
+      tableData.value = (data.records || []).map(mapTemplateFromApi).map((row) => ({
+        ...row,
+        flowSummary: flowNodesSummary(row.flowNodes, row.templateName),
+      }));
       page.total = Number(data.total || 0);
     } catch {
       tableData.value = [];
@@ -186,25 +196,43 @@
       Object.assign(form, base);
       return;
     }
+    const formConfigData = JSON.parse(
+      JSON.stringify(row.formConfigData || parseFormConfigToData(row.formConfig))
+    );
+    const builtin = isBuiltinTemplate(row);
     Object.assign(form, {
       ...base,
       id: row.id,
       templateName: row.templateName || "",
       description: row.description || "",
-      templateType: row.templateType ?? TEMPLATE_TYPE_CUSTOM,
+      templateType: row.templateType != null ? Number(row.templateType) : base.templateType,
+      businessType: row.businessType ?? "",
       formConfig: row.formConfig || "",
-      formConfigData: JSON.parse(
-        JSON.stringify(row.formConfigData || parseFormConfigToData(row.formConfig))
-      ),
+      formConfigData,
+      lockedFormFieldUids: builtin
+        ? (formConfigData.fields || []).map((f) => f._uid).filter(Boolean)
+        : [],
       enabled: row.enabled !== false,
       flowNodes: JSON.parse(JSON.stringify(row.flowNodes || [base.flowNodes[0]])),
+      storageBlobDTOs: JSON.parse(JSON.stringify(row.storageBlobDTOs || [])),
     });
   }
 
-  function openFormDialog(mode, row) {
+  async function openFormDialog(mode, row) {
     formDialog.mode = mode;
     formDialog.title = mode === "add" ? "鏂板缓瀹℃壒妯℃澘" : "缂栬緫瀹℃壒妯℃澘";
-    resetForm(mode === "edit" ? row : null);
+    if (mode === "edit" && row?.id) {
+      // 缂栬緫鏃跺厛鏌ヨ璇︽儏鑾峰彇瀹屾暣鏁版嵁锛堝寘鍚檮浠讹級
+      try {
+        const res = await getApprovalTemplateDetail(row.id);
+        const detailData = mapTemplateFromApi(unwrapTemplateDetail(res));
+        resetForm(detailData);
+      } catch {
+        resetForm(row);
+      }
+    } else {
+      resetForm(mode === "edit" ? row : null);
+    }
     formDialog.visible = true;
   }
 
@@ -253,13 +281,14 @@
     formDialog.visible = false;
     page.current = 1;
     await fetchTemplateList();
-    if (dto.templateType === TEMPLATE_TYPE_BUILTIN) {
-      await loadBuiltinTemplates();
-    }
     return { ok: true };
   }
 
   async function removeTemplate(row) {
+    if (isBuiltinTemplate(row)) {
+      ElMessage.warning("绯荤粺鍐呯疆妯℃澘涓嶅厑璁稿垹闄�");
+      return;
+    }
     if (row?.id == null || row.id === "") {
       ElMessage.warning("鏃犳硶鍒犻櫎锛氱己灏戞ā鏉� ID");
       return;
@@ -284,9 +313,6 @@
       await deleteApprovalTemplate([row.id]);
       ElMessage.success("鍒犻櫎鎴愬姛");
       await fetchTemplateList();
-      if (row.templateType === TEMPLATE_TYPE_BUILTIN) {
-        await loadBuiltinTemplates();
-      }
     } catch {
       /* 閿欒鐢辨嫤鎴櫒鎻愮ず */
     }
@@ -294,14 +320,12 @@
 
   return {
     Search,
-    TEMPLATE_TYPE_OPTIONS,
+    templateTypeOptions,
+    loadTemplateTypeOptions,
     templateTypeLabel,
-    activeTab,
-    builtinTemplates,
-    builtinLoading,
-    loadBuiltinTemplates,
     fetchTemplateList,
     nodeSignModeLabel,
+    nodeDisplayName,
     flowNodesSummary,
     searchForm,
     tableLoading,
@@ -312,6 +336,7 @@
     form,
     formRef,
     formRules,
+    isEditingBuiltin,
     detailDialog,
     detailRow,
     detailLoading,

--
Gitblit v1.9.3