From 07d766a545881be779de94a800f6494ec46c1001 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期二, 19 五月 2026 17:10:08 +0800
Subject: [PATCH] 模板类型接口获取
---
src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js | 102 +++++++++++++++++++++++++++++++++------------------
1 files changed, 66 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..3e27afb 100644
--- a/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
+++ b/src/views/officeProcessAutomation/ApproveManage/approve-template/useApproveTemplate.js
@@ -2,13 +2,11 @@
addApprovalTemplate,
deleteApprovalTemplate,
getApprovalTemplateDetail,
- listApprovalTemplate,
listApprovalTemplatePage,
- TEMPLATE_TYPE_BUILTIN,
TEMPLATE_TYPE_CUSTOM,
- TEMPLATE_TYPE_OPTIONS,
updateApprovalTemplate,
} from "@/api/officeProcessAutomation/approvalTemplate.js";
+import { getTypeEnums } from "@/api/basicData/enum.js";
import { Search } from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { reactive, ref } from "vue";
@@ -16,12 +14,9 @@
buildApprovalTemplateListParams,
createEmptyTemplateForm,
flowNodesSummary,
- mapBuiltinCardFromApi,
mapTemplateFromApi,
mapTemplateToApi,
nodeSignModeLabel,
- templateTypeLabel,
- unwrapTemplateList,
formatDisplayTime,
unwrapTemplateDetail,
validateTemplateForm,
@@ -29,6 +24,44 @@
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 unwrapEnumList(data) {
+ if (Array.isArray(data)) return data;
+ if (!data || typeof data !== "object") return [];
+ if (Array.isArray(data.TypeEnums)) return data.TypeEnums;
+ if (Array.isArray(data.typeEnums)) return data.typeEnums;
+ const nested = Object.values(data).find((v) => Array.isArray(v));
+ return nested || [];
+}
+
+function normalizeTypeEnumOptions(data) {
+ return unwrapEnumList(data)
+ .map((item) => {
+ const rawValue = item?.value ?? item?.code ?? item?.businessType ?? item?.dictValue ?? item?.key;
+ if (rawValue == null || rawValue === "") return null;
+ const num = Number(rawValue);
+ const value =
+ typeof rawValue === "number" || (Number.isFinite(num) && String(rawValue).trim() !== "")
+ ? num
+ : rawValue;
+ const label =
+ item?.label ?? item?.name ?? item?.desc ?? item?.dictLabel ?? item?.text ?? String(value);
+ return { label, value };
+ })
+ .filter(Boolean);
+}
+
+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 +74,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 +97,33 @@
const form = reactive(createEmptyTemplateForm());
const formRef = ref();
+ async function loadTemplateTypeOptions() {
+ try {
+ const res = await getTypeEnums();
+ const list = normalizeTypeEnumOptions(res?.data);
+ 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 +185,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,7 +230,7 @@
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))
@@ -253,9 +292,6 @@
formDialog.visible = false;
page.current = 1;
await fetchTemplateList();
- if (dto.templateType === TEMPLATE_TYPE_BUILTIN) {
- await loadBuiltinTemplates();
- }
return { ok: true };
}
@@ -284,9 +320,6 @@
await deleteApprovalTemplate([row.id]);
ElMessage.success("鍒犻櫎鎴愬姛");
await fetchTemplateList();
- if (row.templateType === TEMPLATE_TYPE_BUILTIN) {
- await loadBuiltinTemplates();
- }
} catch {
/* 閿欒鐢辨嫤鎴櫒鎻愮ず */
}
@@ -294,12 +327,9 @@
return {
Search,
- TEMPLATE_TYPE_OPTIONS,
+ templateTypeOptions,
+ loadTemplateTypeOptions,
templateTypeLabel,
- activeTab,
- builtinTemplates,
- builtinLoading,
- loadBuiltinTemplates,
fetchTemplateList,
nodeSignModeLabel,
flowNodesSummary,
--
Gitblit v1.9.3