2025-08-05 18:00:45 +08:00
|
|
|
// 文件相关工具函数
|
2026-01-15 06:01:34 +08:00
|
|
|
import {
|
|
|
|
|
FileTextFilled,
|
|
|
|
|
FileMarkdownFilled,
|
|
|
|
|
FilePdfFilled,
|
|
|
|
|
FileWordFilled,
|
|
|
|
|
FileExcelFilled,
|
|
|
|
|
FileImageFilled,
|
|
|
|
|
FileUnknownFilled,
|
|
|
|
|
FilePptFilled
|
|
|
|
|
} from '@ant-design/icons-vue'
|
|
|
|
|
import { formatRelative, parseToShanghai } from '@/utils/time'
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// 根据文件扩展名获取文件图标
|
|
|
|
|
export const getFileIcon = (filename) => {
|
|
|
|
|
if (!filename) return FileUnknownFilled
|
|
|
|
|
|
|
|
|
|
const extension = filename.toLowerCase().split('.').pop()
|
|
|
|
|
|
|
|
|
|
const iconMap = {
|
|
|
|
|
// 文本文件
|
2026-01-15 06:01:34 +08:00
|
|
|
txt: FileTextFilled,
|
|
|
|
|
text: FileTextFilled,
|
|
|
|
|
log: FileTextFilled,
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// Markdown文件
|
2026-01-15 06:01:34 +08:00
|
|
|
md: FileMarkdownFilled,
|
|
|
|
|
markdown: FileMarkdownFilled,
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// PDF文件
|
2026-01-15 06:01:34 +08:00
|
|
|
pdf: FilePdfFilled,
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// Word文档
|
2026-01-15 06:01:34 +08:00
|
|
|
doc: FileWordFilled,
|
|
|
|
|
docx: FileWordFilled,
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// Excel文档
|
2026-01-15 06:01:34 +08:00
|
|
|
xls: FileExcelFilled,
|
|
|
|
|
xlsx: FileExcelFilled,
|
|
|
|
|
csv: FileExcelFilled,
|
2025-08-05 18:00:45 +08:00
|
|
|
|
2026-01-15 00:29:00 +08:00
|
|
|
// PPT文档
|
2026-01-15 06:01:34 +08:00
|
|
|
ppt: FilePptFilled,
|
|
|
|
|
pptx: FilePptFilled,
|
2026-01-15 00:29:00 +08:00
|
|
|
|
2025-08-05 18:00:45 +08:00
|
|
|
// 图片文件
|
2026-01-15 06:01:34 +08:00
|
|
|
jpg: FileImageFilled,
|
|
|
|
|
jpeg: FileImageFilled,
|
|
|
|
|
png: FileImageFilled,
|
|
|
|
|
gif: FileImageFilled,
|
|
|
|
|
bmp: FileImageFilled,
|
|
|
|
|
svg: FileImageFilled,
|
|
|
|
|
webp: FileImageFilled,
|
2025-10-25 16:01:50 +08:00
|
|
|
|
|
|
|
|
// HTML文件
|
2026-01-15 06:01:34 +08:00
|
|
|
html: FileTextFilled,
|
|
|
|
|
htm: FileTextFilled
|
2025-08-05 18:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iconMap[extension] || FileUnknownFilled
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据文件扩展名获取文件图标颜色
|
|
|
|
|
export const getFileIconColor = (filename) => {
|
|
|
|
|
if (!filename) return '#8c8c8c'
|
|
|
|
|
|
|
|
|
|
const extension = filename.toLowerCase().split('.').pop()
|
|
|
|
|
|
|
|
|
|
const colorMap = {
|
|
|
|
|
// 文本文件 - 蓝色
|
2026-01-15 06:01:34 +08:00
|
|
|
txt: '#1890ff',
|
|
|
|
|
text: '#1890ff',
|
|
|
|
|
log: '#1890ff',
|
2025-08-05 18:00:45 +08:00
|
|
|
|
2026-01-15 04:54:53 +08:00
|
|
|
// Markdown文件 - 深灰色
|
2026-01-15 06:01:34 +08:00
|
|
|
md: '#595959',
|
|
|
|
|
markdown: '#595959',
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// PDF文件 - 红色
|
2026-01-15 06:01:34 +08:00
|
|
|
pdf: '#ff4d4f',
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// Word文档 - 深蓝色
|
2026-01-15 06:01:34 +08:00
|
|
|
doc: '#2f54eb',
|
|
|
|
|
docx: '#2f54eb',
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// Excel文档 - 绿色
|
2026-01-15 06:01:34 +08:00
|
|
|
xls: '#52c41a',
|
|
|
|
|
xlsx: '#52c41a',
|
|
|
|
|
csv: '#52c41a',
|
2025-08-05 18:00:45 +08:00
|
|
|
|
2026-01-15 00:29:00 +08:00
|
|
|
// PPT文档 - 橙色
|
2026-01-15 06:01:34 +08:00
|
|
|
ppt: '#f6720d',
|
|
|
|
|
pptx: '#f6720d',
|
2026-01-15 00:29:00 +08:00
|
|
|
|
2025-08-05 18:00:45 +08:00
|
|
|
// 图片文件 - 紫色
|
2026-01-15 06:01:34 +08:00
|
|
|
jpg: '#722ed1',
|
|
|
|
|
jpeg: '#722ed1',
|
|
|
|
|
png: '#722ed1',
|
|
|
|
|
gif: '#722ed1',
|
|
|
|
|
bmp: '#722ed1',
|
|
|
|
|
svg: '#722ed1',
|
|
|
|
|
webp: '#722ed1',
|
2025-10-25 16:01:50 +08:00
|
|
|
|
|
|
|
|
// HTML文件 - 橙色
|
2026-01-15 06:01:34 +08:00
|
|
|
html: '#fa8c16',
|
|
|
|
|
htm: '#fa8c16'
|
2025-08-05 18:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return colorMap[extension] || '#8c8c8c'
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 15:08:54 +08:00
|
|
|
// Format relative time with CST baseline
|
|
|
|
|
export const formatRelativeTime = (value) => formatRelative(value)
|
2025-08-05 18:00:45 +08:00
|
|
|
|
|
|
|
|
// 格式化标准时间
|
2025-10-13 15:08:54 +08:00
|
|
|
export const formatStandardTime = (value) => {
|
|
|
|
|
const parsed = parseToShanghai(value)
|
|
|
|
|
if (!parsed) return '-'
|
|
|
|
|
return parsed.format('YYYY年MM月DD日 HH:mm:ss')
|
2025-08-05 18:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取状态文本
|
|
|
|
|
export const getStatusText = (status) => {
|
|
|
|
|
const statusMap = {
|
2026-01-15 06:01:34 +08:00
|
|
|
done: '处理完成',
|
|
|
|
|
failed: '处理失败',
|
|
|
|
|
processing: '处理中',
|
|
|
|
|
waiting: '等待处理'
|
2025-08-05 18:00:45 +08:00
|
|
|
}
|
2026-01-04 21:35:25 +08:00
|
|
|
return map[status] || status
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化文件大小
|
|
|
|
|
export const formatFileSize = (bytes) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
if (bytes === 0 || bytes === '0') return '0 B'
|
|
|
|
|
if (!bytes) return '-'
|
|
|
|
|
const k = 1024
|
|
|
|
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
2025-10-13 15:08:54 +08:00
|
|
|
}
|