Private
Public Access
1
0

重构: 死代码清理 + 拷贝优化 + 滚动条修复

This commit is contained in:
2026-04-11 23:36:08 +08:00
parent 7dbd57a8b6
commit 756028af0f
39 changed files with 185 additions and 1308 deletions

View File

@@ -11,7 +11,7 @@ import { FILE_ICON_MAP, FILE_ICONS, BYTE_UNITS, FILE_SIZE_FORMAT } from './const
* 路径分隔符正则(匹配 Windows 和 Unix 风格)
* @type {RegExp}
*/
export const PATH_SEPARATOR_REGEX = /[/\\]/
const PATH_SEPARATOR_REGEX = /[/\\]/
/**
* 规范化路径分隔符(统一为正斜杠)
@@ -93,26 +93,6 @@ export function getFileName(path) {
return parts[parts.length - 1] || path
}
/**
* 分割路径为多个部分
* @param {string} path - 文件路径
* @returns {string[]} 路径数组
*/
export const splitPath = (path) => {
if (!path) return []
return path.split(PATH_SEPARATOR_REGEX)
}
/**
* 获取文件名(不含扩展名)
* @param {string} path - 文件路径
* @returns {string} 文件名(不含扩展名)
*/
export const getFileNameWithoutExt = (path) => {
const fileName = getFileName(path)
const lastDot = fileName.lastIndexOf('.')
return lastDot > 0 ? fileName.substring(0, lastDot) : fileName
}
/**
* 根据文件信息获取对应的图标
@@ -177,89 +157,6 @@ export function normalizeFilePath(path, encode = false) {
return normalized
}
/**
* 获取文件类型的友好名称
* @param {string} path - 文件路径
* @returns {string} 文件类型名称
*
* @example
* getFileTypeName('image.png') // "PNG图片"
* getFileTypeName('document.pdf') // "PDF文档"
* getFileTypeName('unknown.xyz') // "XYZ文件"
*/
export function getFileTypeName(path) {
const ext = getExt(path)
const extUpper = ext.toUpperCase()
// 图片
if (['JPG', 'JPEG', 'PNG', 'GIF', 'BMP', 'SVG', 'WEBP'].includes(extUpper)) {
return `${extUpper}图片`
}
// 视频
if (['MP4', 'WEBM', 'AVI', 'MKV'].includes(extUpper)) {
return `${extUpper}视频`
}
// 音频
if (['MP3', 'WAV', 'FLAC', 'AAC'].includes(extUpper)) {
return `${extUpper}音频`
}
// PDF
if (extUpper === 'PDF') {
return 'PDF文档'
}
// 文档
if (['DOC', 'DOCX', 'XLS', 'XLSX', 'PPT', 'PPTX'].includes(extUpper)) {
return `${extUpper}文档`
}
// 代码
if (['JS', 'TS', 'PY', 'JAVA', 'GO', 'RS', 'CPP'].includes(extUpper)) {
return `${extUpper}代码`
}
// 默认返回扩展名
return ext ? `${extUpper}文件` : '文件'
}
/**
* 检查路径是否为绝对路径
* @param {string} path - 文件路径
* @returns {boolean} 是否为绝对路径
*
* @example
* isAbsolutePath('C:\\Users') // true (Windows)
* isAbsolutePath('/home/user') // true (Unix)
* isAbsolutePath('folder/file') // false
*/
export function isAbsolutePath(path) {
if (!path) return false
// Windows路径盘符开头
if (/^[A-Za-z]:\\/.test(path)) return true
// Unix路径以 / 开头
if (path.startsWith('/')) return true
return false
}
/**
* 拼接路径片段
* @param {...string} parts - 路径片段
* @returns {string} 拼接后的路径
*
* @example
* joinPaths('/home', 'user', 'docs') // "/home/user/docs"
* joinPaths('C:\\Users', 'user') // "C:\\Users\\user"
*/
export function joinPaths(...parts) {
return parts.join('/').replace(/\/+/g, '/')
}
/**
* 获取路径使用的分隔符Windows 反斜杠或 Unix 正斜杠)
* @param {string} path - 文件路径
@@ -301,24 +198,6 @@ export function getParentPath(path) {
return parentPath || '/'
}
/**
* 清理文件名,移除非法字符
* @param {string} filename - 原始文件名
* @param {string} [replacement='_'] - 替换字符
* @returns {string} 清理后的文件名
*
* @example
* sanitizeFileName('file/name.txt') // "file_name.txt"
* sanitizeFileName('file:name.txt', '-') // "file-name.txt"
*/
export function sanitizeFileName(filename, replacement = '_') {
if (!filename) return ''
// Windows不允许的字符: < > : " / \ | ? *
const illegalChars = /[<>:"/\\|?*]/g
return filename.replace(illegalChars, replacement)
}
/**
* 文件列表排序:文件夹优先,支持多字段排序