| | |
| | | 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 { |
| | | buildApprovalTemplateListParams, |
| | | createEmptyTemplateForm, |
| | | fetchBusinessTypeOptions, |
| | | flowNodesSummary, |
| | | mapBuiltinCardFromApi, |
| | | mapTemplateFromApi, |
| | | mapTemplateToApi, |
| | | nodeSignModeLabel, |
| | | templateTypeLabel, |
| | | unwrapTemplateList, |
| | | formatDisplayTime, |
| | | unwrapTemplateDetail, |
| | | validateTemplateForm, |
| | |
| | | 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 { |
| | |
| | | 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: "", |
| | |
| | | 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), |
| | |
| | | }, |
| | | ]); |
| | | |
| | | 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 { |
| | |
| | | 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)) |
| | |
| | | formDialog.visible = false; |
| | | page.current = 1; |
| | | await fetchTemplateList(); |
| | | if (dto.templateType === TEMPLATE_TYPE_BUILTIN) { |
| | | await loadBuiltinTemplates(); |
| | | } |
| | | return { ok: true }; |
| | | } |
| | | |
| | |
| | | await deleteApprovalTemplate([row.id]); |
| | | ElMessage.success("删除成功"); |
| | | await fetchTemplateList(); |
| | | if (row.templateType === TEMPLATE_TYPE_BUILTIN) { |
| | | await loadBuiltinTemplates(); |
| | | } |
| | | } catch { |
| | | /* 错误由拦截器提示 */ |
| | | } |
| | |
| | | |
| | | return { |
| | | Search, |
| | | TEMPLATE_TYPE_OPTIONS, |
| | | templateTypeOptions, |
| | | loadTemplateTypeOptions, |
| | | templateTypeLabel, |
| | | activeTab, |
| | | builtinTemplates, |
| | | builtinLoading, |
| | | loadBuiltinTemplates, |
| | | fetchTemplateList, |
| | | nodeSignModeLabel, |
| | | flowNodesSummary, |