| | |
| | | import dayjs from "dayjs"; |
| | | import { |
| | | TEMPLATE_TYPE_CUSTOM, |
| | | TEMPLATE_TYPE_OPTIONS, |
| | | } from "@/api/officeProcessAutomation/approvalTemplate.js"; |
| | | import { getTypeEnums } from "@/api/basicData/enum.js"; |
| | | import { TEMPLATE_TYPE_CUSTOM } from "@/api/officeProcessAutomation/approvalTemplate.js"; |
| | | import { APPROVAL_TYPE_OPTIONS } from "../approve-list/approveListConstants.js"; |
| | | import { |
| | | buildFormConfigJson, |
| | |
| | | validateFormConfigData, |
| | | } from "./formConfigUtils.js"; |
| | | |
| | | export { TEMPLATE_TYPE_OPTIONS }; |
| | | export 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 || []; |
| | | } |
| | | |
| | | export function templateTypeLabel(type) { |
| | | if (type == null || type === "") return "—"; |
| | | const n = Number(type); |
| | | return TEMPLATE_TYPE_OPTIONS.find((x) => x.value === n)?.label || "—"; |
| | | export function normalizeBusinessTypeOptions(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); |
| | | } |
| | | |
| | | export async function fetchBusinessTypeOptions() { |
| | | try { |
| | | const res = await getTypeEnums(); |
| | | return normalizeBusinessTypeOptions(res?.data); |
| | | } catch { |
| | | return []; |
| | | } |
| | | } |
| | | |
| | | /** 节点内审批方式:会签 / 或签 */ |
| | |
| | | return data; |
| | | } |
| | | |
| | | /** 后端附件字段 → 页面 storageBlobDTOs */ |
| | | export function mapAttachmentsFromApi(row) { |
| | | const list = |
| | | row?.storageBlobDTOs || |
| | | row?.storageBlobDTOS || |
| | | row?.storageBlobVOS || |
| | | row?.storageBlobVOList || |
| | | row?.attachmentList || |
| | | []; |
| | | return Array.isArray(list) ? list : []; |
| | | } |
| | | |
| | | /** 分页列表项 → 页面行数据(主表 + 节点) */ |
| | | export function mapTemplateFromApi(row) { |
| | | if (!row) return {}; |
| | |
| | | enabled: mapEnabledFromApi(row.enabled), |
| | | enabledRaw: row.enabled, |
| | | templateType: row.templateType != null ? Number(row.templateType) : undefined, |
| | | businessType: row.businessType ?? "", |
| | | formConfig: row.formConfig, |
| | | formConfigData: parseFormConfigToData(row.formConfig), |
| | | storageBlobDTOs: mapAttachmentsFromApi(row), |
| | | createdUser: row.createdUser, |
| | | createdUserName: row.createdUserName, |
| | | ...times, |
| | |
| | | templateName: (form.templateName || "").trim(), |
| | | description: (form.description || "").trim(), |
| | | enabled: mapEnabledToApi(form.enabled), |
| | | templateType: form.templateType ?? TEMPLATE_TYPE_CUSTOM, |
| | | templateType: TEMPLATE_TYPE_CUSTOM, |
| | | businessType: form.businessType ?? "", |
| | | formConfig: buildFormConfigJson(form.formConfigData), |
| | | nodes: nodes.map((n, i) => { |
| | | const node = { |
| | |
| | | }), |
| | | }; |
| | | if (templateId) dto.id = templateId; |
| | | const attachments = Array.isArray(form.storageBlobDTOs) ? form.storageBlobDTOs : []; |
| | | if (attachments.length) dto.storageBlobDTOs = attachments; |
| | | return dto; |
| | | } |
| | | |
| | |
| | | templateName: "", |
| | | description: "", |
| | | templateType: TEMPLATE_TYPE_CUSTOM, |
| | | businessType: "", |
| | | formConfig: "", |
| | | formConfigData: createEmptyFormConfigData(), |
| | | enabled: true, |
| | | flowNodes: [createEmptyNode(1)], |
| | | storageBlobDTOs: [], |
| | | }; |
| | | } |
| | | |
| | |
| | | export function validateTemplateForm(form) { |
| | | const name = (form.templateName || "").trim(); |
| | | if (!name) return { ok: false, message: "请填写模板名称" }; |
| | | if (form.businessType == null || form.businessType === "") { |
| | | return { ok: false, message: "请选择模板类型" }; |
| | | } |
| | | const nodes = normalizeFlowNodes(form.flowNodes); |
| | | if (!nodes.length) return { ok: false, message: "请至少配置一个审批节点" }; |
| | | for (let i = 0; i < nodes.length; i++) { |