Blame view

机具(管理端)/src/utils/fileIcon.js 1.44 KB
5a92a12b   “wangming”   项目初始化
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
  /**
   * 根据文件名或扩展名返回文件类型图标 classicon-ym-file-xxx
   * 视频使用 icon-ym-file-video,避免与 PDF 图标混淆
   * @param {string} nameOrExt - 文件名(如 "a.mp4")或扩展名(如 "mp4"  ".mp4"
   * @returns {string} 图标 class 名,如 "icon-ym-file-video"
   */
  export function getFileIconClass(nameOrExt) {
    if (!nameOrExt) return 'icon-ym-file-blank'
    let ext = typeof nameOrExt === 'string' ? nameOrExt.trim() : ''
    if (ext.indexOf('.') !== -1) {
      ext = ext.split('.').pop() || ''
    }
    ext = ext.toLowerCase()
  
    if (ext === 'doc' || ext === 'docx') return 'icon-ym-file-word'
    if (ext === 'xls' || ext === 'xlsx') return 'icon-ym-file-excel'
    if (ext === 'ppt' || ext === 'pptx') return 'icon-ym-file-ppt'
    if (ext === 'rar' || ext === 'zip') return 'icon-ym-file-zip'
    if (ext === 'txt' || ext === 'log') return 'icon-ym-file-text'
    if (ext === 'html' || ext === 'cs' || ext === 'xml') return 'icon-ym-file-code'
    if (['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp'].indexOf(ext) !== -1) return 'icon-ym-file-image1'
    if (ext === 'pdf') return 'icon-ym-file-pdf'
    if (ext === 'mp3' || ext === 'wav' || ext === 'ogg') return 'icon-ym-file-audio'
    // 视频统一使用 file-video 图标(不用 file-movie,避免与 PDF 图标混淆)
    if (['mp4', 'avi', 'mov', 'wmv', 'webm', 'mkv', 'flv', 'm4v', '3gp'].indexOf(ext) !== -1) {
      return 'icon-ym-file-video'
    }
    return 'icon-ym-file-blank'
  }