export const ALLOWED_EXTENSIONS = ['pdf','doc','docx','xls','xlsx','ppt','pptx','txt','md','csv'] export const ACCEPT = ALLOWED_EXTENSIONS.map(ext => `.${ext}`).join(',') export const MAX_FILE_SIZE = 50 * 1024 * 1024 export function validateBackgroundFile(file) { if (!file || !file.name || file.size === 0) return '请选择非空文件' if (file.name.length > 255) return '文件名不能超过255个字符' const ext = file.name.includes('.') ? file.name.split('.').pop().toLowerCase() : '' if (!ALLOWED_EXTENSIONS.includes(ext)) return '文件类型不支持' if (file.size > MAX_FILE_SIZE) return '单个文件不能超过50MB' return '' } export function formatFileSize(bytes) { if (!bytes) return '0 B' if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${Number((bytes / 1024).toFixed(1))} KB` return `${Number((bytes / 1024 / 1024).toFixed(1))} MB` }