优化:移除重复逻辑和语法高亮支持
- 提取文件列表排序公共函数 sortFileList - 统一应用文件夹优先排序规则 - 移除生产环境 source map,减小打包体积 - 提升代码可维护性
This commit is contained in:
@@ -320,3 +320,25 @@ export function sanitizeFileName(filename, replacement = '_') {
|
||||
|
||||
return filename.replace(illegalChars, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件列表排序:文件夹优先,同类型按名称排序
|
||||
* @param {Array} fileList - 文件列表
|
||||
* @returns {Array} 排序后的文件列表
|
||||
*
|
||||
* @example
|
||||
* sortFileList([{name: 'b.txt', is_dir: false}, {name: 'a', is_dir: true}])
|
||||
* // [{name: 'a', is_dir: true}, {name: 'b.txt', is_dir: false}]
|
||||
*/
|
||||
export function sortFileList(fileList) {
|
||||
if (!Array.isArray(fileList)) return fileList
|
||||
|
||||
return fileList.sort((a, b) => {
|
||||
// 如果都是目录或都是文件,按名称排序
|
||||
if (a.is_dir === b.is_dir) {
|
||||
return a.name.localeCompare(b.name)
|
||||
}
|
||||
// 目录优先
|
||||
return a.is_dir ? -1 : 1
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user