| | |
| | | import dayjs from "dayjs"; |
| | | 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 { |
| | |
| | | parseFormConfigToData, |
| | | validateFormConfigData, |
| | | } from "./formConfigUtils.js"; |
| | | |
| | | 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 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 []; |
| | | } |
| | | } |
| | | |
| | | /** 节点内审批方式:会签 / 或签 */ |
| | | export const NODE_SIGN_MODE_OPTIONS = [ |
| | |
| | | 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 {}; |
| | |
| | | businessType: row.businessType ?? "", |
| | | formConfig: row.formConfig, |
| | | formConfigData: parseFormConfigToData(row.formConfig), |
| | | storageBlobDTOs: mapAttachmentsFromApi(row), |
| | | createdUser: row.createdUser, |
| | | createdUserName: row.createdUserName, |
| | | ...times, |
| | |
| | | }), |
| | | }; |
| | | if (templateId) dto.id = templateId; |
| | | const attachments = Array.isArray(form.storageBlobDTOs) ? form.storageBlobDTOs : []; |
| | | if (attachments.length) dto.storageBlobDTOs = attachments; |
| | | return dto; |
| | | } |
| | | |
| | |
| | | formConfigData: createEmptyFormConfigData(), |
| | | enabled: true, |
| | | flowNodes: [createEmptyNode(1)], |
| | | storageBlobDTOs: [], |
| | | }; |
| | | } |
| | | |