yyb
14 小时以前 6689bfb1c2f0638e8493adfa058d57d86e473eac
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,7 +203,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 +265,6 @@
    formDialog.visible = false;
    page.current = 1;
    await fetchTemplateList();
    if (dto.templateType === TEMPLATE_TYPE_BUILTIN) {
      await loadBuiltinTemplates();
    }
    return { ok: true };
  }
@@ -284,9 +293,6 @@
      await deleteApprovalTemplate([row.id]);
      ElMessage.success("删除成功");
      await fetchTemplateList();
      if (row.templateType === TEMPLATE_TYPE_BUILTIN) {
        await loadBuiltinTemplates();
      }
    } catch {
      /* 错误由拦截器提示 */
    }
@@ -294,12 +300,9 @@
  return {
    Search,
    TEMPLATE_TYPE_OPTIONS,
    templateTypeOptions,
    loadTemplateTypeOptions,
    templateTypeLabel,
    activeTab,
    builtinTemplates,
    builtinLoading,
    loadBuiltinTemplates,
    fetchTemplateList,
    nodeSignModeLabel,
    flowNodesSummary,