/** * 从审批 / 业务详情的原始接口数据中,兼容多种附件字段来源, * 解析出文件 ID 数组(去重、字符串化)。 * * 兼容的字段来源(按常见命名): * - attachmentIds 字符串(逗号分隔)或字符串数组 * - attachmentFileIds 字符串(逗号分隔)或字符串数组 * - approvalDocumentFileId 单个 ID 或逗号分隔的字符串或数组 * - attachmentFileId 同上 * - resumeAttachmentFileIds 同上 * - files / attachments 对象数组,元素含 fileId / id,或本身就是 ID 字符串 * * 这样无论后端接口用哪种字段返回附件,前端都能正确拿到可预览的文件 ID 列表。 */ export function parseAttachmentIds(raw) { raw = raw || {}; const ids = []; const collect = (value) => { if (value == null || value === '') return; const list = Array.isArray(value) ? value : String(value) .split(',') .map((s) => s.trim()); list.forEach((item) => { if (item == null || item === '') return; const id = typeof item === 'object' ? item.fileId || item.id : String(item).trim(); if (id && !ids.includes(String(id))) ids.push(String(id)); }); }; collect(raw.attachmentIds); collect(raw.attachmentFileIds); collect(raw.approvalDocumentFileId); collect(raw.attachmentFileId); collect(raw.resumeAttachmentFileIds); if (Array.isArray(raw.files)) collect(raw.files); if (Array.isArray(raw.attachments)) collect(raw.attachments); return ids; }