新增:文件系统导航面包屑
功能: - 新增 PathBreadcrumb 组件,支持路径快速跳转 - 新增 DropdownItem 通用下拉菜单组件 优化: - 版本升级流程优化(Pinia 状态管理、进度节流、完整下载验证) - 模块延迟初始化(数据库、文件系统按需启动) - API 数据格式统一(蛇形转驼峰) - CodeMirror 语言包按需动态加载 - Markdown 渲染增强(支持锚点跳转) 重构: - 迁移到 Pinia 状态管理(stores/config.ts、stores/theme.ts、stores/update.ts) - 简化 UpdatePanel、UpdateNotification、ThemeToggle 逻辑 - 优化表结构加载逻辑 清理: - 删除测试组件 index-simple.vue - 删除旧的 useTheme.ts
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* @description 提供文件相关的通用工具函数,避免代码重复
|
||||
*/
|
||||
|
||||
import { normalizePathSeparators } from './pathHelpers.js'
|
||||
import { FILE_ICON_MAP, FILE_ICONS, BYTE_UNITS, FILE_SIZE_FORMAT, FILE_EXTENSIONS } from './constants'
|
||||
|
||||
/**
|
||||
@@ -46,11 +47,8 @@ export function formatBytes(bytes) {
|
||||
export function getFileName(path) {
|
||||
if (!path) return ''
|
||||
|
||||
// 统一分隔符为正斜杠
|
||||
const normalizedPath = path.replace(/\\/g, '/')
|
||||
|
||||
// 分割路径并取最后一部分
|
||||
const parts = normalizedPath.split('/')
|
||||
// 后端已统一返回 / 路径,直接分割
|
||||
const parts = path.split('/')
|
||||
|
||||
return parts[parts.length - 1] || path
|
||||
}
|
||||
@@ -157,7 +155,7 @@ export function isPdfFile(path) {
|
||||
*/
|
||||
export function normalizeFilePath(path, encode = false) {
|
||||
if (!path) return ''
|
||||
const normalized = path.replace(/\\/g, '/')
|
||||
const normalized = normalizePathSeparators(path)
|
||||
|
||||
// 如果需要编码,则使用 encodeURIComponent
|
||||
if (encode) {
|
||||
@@ -327,18 +325,17 @@ export function sanitizeFileName(filename, replacement = '_') {
|
||||
* @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}]
|
||||
* sortFileList([{name: 'b.txt', isDir: false}, {name: 'a', isDir: true}])
|
||||
* // [{name: 'a', isDir: true}, {name: 'b.txt', isDir: false}]
|
||||
*/
|
||||
export function sortFileList(fileList) {
|
||||
if (!Array.isArray(fileList)) return fileList
|
||||
|
||||
return fileList.sort((a, b) => {
|
||||
// 如果都是目录或都是文件,按名称排序
|
||||
if (a.is_dir === b.is_dir) {
|
||||
// API 层已转换,直接使用 isDir
|
||||
if (a.isDir === b.isDir) {
|
||||
return a.name.localeCompare(b.name)
|
||||
}
|
||||
// 目录优先
|
||||
return a.is_dir ? -1 : 1
|
||||
return a.isDir ? -1 : 1
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user