teamBackgroundFile.js 902 B

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