(function validateDmsFileSizes({ formData, onlineUtils }) { const fail = message => { onlineUtils.toast(message, 'warning'); throw new Error(message); }; const list = (value, label) => { if (value === undefined || value === null || value === '') return []; if (Array.isArray(value)) return value; if (typeof value === 'string') { try { const parsed = JSON.parse(value); if (Array.isArray(parsed)) return parsed; } catch (_) { // A malformed attachment value must not silently become an empty list. } } return fail(label + '数据无法读取,请重新打开表单后再提交'); }; const check = (value, label) => { for (const file of list(value, label)) { const name = typeof file?.name === 'string' && file.name.trim() ? '“' + file.name.trim() + '”' : ''; const rawSize = file?.fileSize; // Use the current attachment supplied by upload-edit, never the original // upload or the display-only *_jnpfId snapshot. Missing size is not zero. if ((typeof rawSize !== 'number' && typeof rawSize !== 'string') || String(rawSize).trim() === '') { fail(label + name + '大小无法确认,请重新打开表单核对附件后再提交'); } const size = Number(rawSize); if (!Number.isFinite(size) || !Number.isInteger(size) || size < 0) { fail(label + name + '大小无效,请重新选择附件后再提交'); } if (size === 0) { const action = /\.docx$/i.test(file?.name || '') ? '请上传有内容的文件,或在线编辑保存后再提交' : '请上传有内容的文件后再提交'; fail(label + name + '为空文件(0 字节),' + action); } } }; check(formData.wenjian, '主文件'); const rows = list(formData.jilu_mingxi, '记录明细'); rows.forEach((row, index) => check(row?.jilu_wenjian, '第 ' + (index + 1) + ' 行记录附件')); })