From 5b248a9716688d8132cfb02b4ba0abecd4060b06 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 20 五月 2026 11:49:08 +0800
Subject: [PATCH] 审批模板流程化

---
 src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js |   76 ++++++++++++++++++++------------------
 1 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
index 8489e13..4b2abe4 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
@@ -2,11 +2,8 @@
   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";
@@ -15,13 +12,11 @@
 import {
   buildApprovalTemplateListParams,
   createEmptyTemplateForm,
+  fetchBusinessTypeOptions,
   flowNodesSummary,
-  mapBuiltinCardFromApi,
   mapTemplateFromApi,
   mapTemplateToApi,
   nodeSignModeLabel,
-  templateTypeLabel,
-  unwrapTemplateList,
   formatDisplayTime,
   unwrapTemplateDetail,
   validateTemplateForm,
@@ -29,6 +24,18 @@
 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 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)
+  );
+}
 
 function clearLegacyStorage() {
   try {
@@ -41,9 +48,15 @@
 export function useApproveTemplate() {
   clearLegacyStorage();
 
-  const activeTab = ref("custom");
-  const builtinTemplates = ref([]);
-  const builtinLoading = ref(false);
+  const templateTypeOptions = ref([...FALLBACK_TEMPLATE_TYPE_OPTIONS]);
+
+  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 +71,32 @@
   const form = reactive(createEmptyTemplateForm());
   const formRef = ref();
 
+  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),
@@ -133,19 +158,6 @@
     },
   ]);
 
-  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;
     try {
@@ -191,13 +203,14 @@
       id: row.id,
       templateName: row.templateName || "",
       description: row.description || "",
-      templateType: row.templateType ?? TEMPLATE_TYPE_CUSTOM,
+      businessType: row.businessType ?? "",
       formConfig: row.formConfig || "",
       formConfigData: JSON.parse(
         JSON.stringify(row.formConfigData || parseFormConfigToData(row.formConfig))
       ),
       enabled: row.enabled !== false,
       flowNodes: JSON.parse(JSON.stringify(row.flowNodes || [base.flowNodes[0]])),
+      storageBlobDTOs: JSON.parse(JSON.stringify(row.storageBlobDTOs || [])),
     });
   }
 
@@ -253,9 +266,6 @@
     formDialog.visible = false;
     page.current = 1;
     await fetchTemplateList();
-    if (dto.templateType === TEMPLATE_TYPE_BUILTIN) {
-      await loadBuiltinTemplates();
-    }
     return { ok: true };
   }
 
@@ -284,9 +294,6 @@
       await deleteApprovalTemplate([row.id]);
       ElMessage.success("鍒犻櫎鎴愬姛");
       await fetchTemplateList();
-      if (row.templateType === TEMPLATE_TYPE_BUILTIN) {
-        await loadBuiltinTemplates();
-      }
     } catch {
       /* 閿欒鐢辨嫤鎴櫒鎻愮ず */
     }
@@ -294,12 +301,9 @@
 
   return {
     Search,
-    TEMPLATE_TYPE_OPTIONS,
+    templateTypeOptions,
+    loadTemplateTypeOptions,
     templateTypeLabel,
-    activeTab,
-    builtinTemplates,
-    builtinLoading,
-    loadBuiltinTemplates,
     fetchTemplateList,
     nodeSignModeLabel,
     flowNodesSummary,

--
Gitblit v1.9.3