From 9f3bc47b98cbc51df7cfcea94d4aa0c35f40cbc5 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 13 十月 2026 14:09:06 +0800
Subject: [PATCH] feat: 添加数字格式化工具,支持去掉小数末尾多余的 0 和四舍五入功能

---
 src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js |   80 +++++++++++++++++++++++++--------------
 1 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
index 95eac7b..df25e2e 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
@@ -3,27 +3,27 @@
   deleteApprovalTemplate,
   getApprovalTemplateDetail,
   listApprovalTemplatePage,
-  TEMPLATE_TYPE_CUSTOM,
+  TEMPLATE_TYPE_BUILTIN,
   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,
+  isBuiltinTemplate,
   mapTemplateFromApi,
   mapTemplateToApi,
+  nodeDisplayName,
   nodeSignModeLabel,
   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: "绯荤粺鍐呯疆" },
@@ -37,17 +37,7 @@
   );
 }
 
-function clearLegacyStorage() {
-  try {
-    localStorage.removeItem(LEGACY_STORAGE_KEY);
-  } catch {
-    /* ignore */
-  }
-}
-
 export function useApproveTemplate() {
-  clearLegacyStorage();
-
   const templateTypeOptions = ref([...FALLBACK_TEMPLATE_TYPE_OPTIONS]);
 
   function templateTypeLabel(type) {
@@ -70,6 +60,10 @@
   const formDialog = reactive({ visible: false, title: "", mode: "add" });
   const form = reactive(createEmptyTemplateForm());
   const formRef = ref();
+
+  const isEditingBuiltin = computed(
+    () => formDialog.mode === "edit" && Number(form.templateType) === TEMPLATE_TYPE_BUILTIN
+  );
 
   async function loadTemplateTypeOptions() {
     try {
@@ -111,10 +105,9 @@
     },
     {
       label: "娴佺▼姒傝",
-      prop: "flowNodes",
+      prop: "flowSummary",
       minWidth: 220,
       showOverflowTooltip: true,
-      formatData: (v) => flowNodesSummary(v),
     },
     {
       label: "鐘舵��",
@@ -132,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: "鎿嶄綔",
@@ -152,6 +145,7 @@
           name: "鍒犻櫎",
           type: "danger",
           link: true,
+          disabled: (row) => isBuiltinTemplate(row),
           clickFun: (row) => removeTemplate(row),
         },
       ],
@@ -165,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 = [];
@@ -198,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 != 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;
   }
 
@@ -269,6 +285,10 @@
   }
 
   async function removeTemplate(row) {
+    if (isBuiltinTemplate(row)) {
+      ElMessage.warning("绯荤粺鍐呯疆妯℃澘涓嶅厑璁稿垹闄�");
+      return;
+    }
     if (row?.id == null || row.id === "") {
       ElMessage.warning("鏃犳硶鍒犻櫎锛氱己灏戞ā鏉� ID");
       return;
@@ -305,6 +325,7 @@
     templateTypeLabel,
     fetchTemplateList,
     nodeSignModeLabel,
+    nodeDisplayName,
     flowNodesSummary,
     searchForm,
     tableLoading,
@@ -315,6 +336,7 @@
     form,
     formRef,
     formRules,
+    isEditingBuiltin,
     detailDialog,
     detailRow,
     detailLoading,

--
Gitblit v1.9.3