Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | // 文件视觉共享工具:扩展名语义配色、图片判断、大小格式化 // 集中此处,避免 FileCard / FileListPanel / FilePreviewPanel 三处重复定义 // 扩展名 → 语义配色(ERP 附件管理可一眼辨类) const EXT_COLOR = { // 文档 pdf: '#f5222d', doc: '#1677ff', docx: '#1677ff', txt: '#8c8c8c', md: '#8c8c8c', // 表格 xls: '#52c41a', xlsx: '#52c41a', csv: '#52c41a', // 演示 ppt: '#fa541c', pptx: '#fa541c', // 图片 jpg: '#722ed1', jpeg: '#722ed1', png: '#722ed1', gif: '#722ed1', bmp: '#722ed1', webp: '#722ed1', svg: '#722ed1', // 压缩 zip: '#fa8c16', rar: '#fa8c16', '7z': '#fa8c16', // 音视频 mp3: '#13c2c2', wav: '#13c2c2', mp4: '#13c2c2', mov: '#13c2c2', } const FALLBACK_COLOR = '#8c8c8c' export function extFromName(name) { const idx = (name || '').lastIndexOf('.') return idx >= 0 ? name.substring(idx + 1).toLowerCase() : '' } export function extColor(name) { const ext = extFromName(name) return EXT_COLOR[ext] || FALLBACK_COLOR } export function isImageType(name) { return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].includes( extFromName(name), ) } export function formatSize(bytes) { const n = Number(bytes || 0) if (n < 1024) return n + ' B' if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB' if (n < 1024 * 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + ' MB' return (n / (1024 * 1024 * 1024)).toFixed(2) + ' GB' } |