重构: App拆分10域文件+并发安全+结构化日志+依赖升级

This commit is contained in:
lxy
2026-05-16 20:45:14 +08:00
parent d17c20c579
commit 767311fc04
27 changed files with 1457 additions and 1218 deletions
@@ -445,10 +445,15 @@ import { parseLrc, type LrcLine } from '@/utils/lrcParser'
import BgmBar, { type BgmTrack } from './FileEditor/BgmBar.vue'
// 异步加载 CodeEditor 组件,减少初始包大小
let editorRetryCount = 0
const AsyncCodeEditor = defineAsyncComponent({
loader: () => import('@/components/CodeEditor.vue'),
delay: 200,
timeout: 10000
timeout: 10000,
onError(error, retry) {
console.error('[AsyncCodeEditor] 加载失败:', error)
if (++editorRetryCount <= 2) retry()
}
})
// Office 预览容器引用
@@ -499,6 +499,7 @@ ${ext ? `文件类型: ${fileTypeDesc}\n` : ''}
const clearContent = () => {
fileContent.value = ''
originalContent.value = ''
isBinaryFile.value = false
}
/**
@@ -22,6 +22,7 @@ const CONTENT_DETECT_MAX_SIZE = 500 * 1024 // 500KB
// 缓存检测结果
const contentDetectCache = new Map<string, { timestamp: number; result: any }>()
const CACHE_TTL = 60000 // 1分钟缓存
const CACHE_MAX_SIZE = 200
// ====== URL 工具函数(导出供外部使用) ======
@@ -122,6 +123,7 @@ export function useFilePreview() {
try {
const result = await detectFileTypeByContent(path)
const data = { category: result.category, ext: result.extension }
if (contentDetectCache.size >= CACHE_MAX_SIZE) contentDetectCache.clear()
contentDetectCache.set(path, { timestamp: Date.now(), result: data })
return data
} catch {
@@ -1158,6 +1158,14 @@ const activateTab = async (tab: PreviewTab) => {
}
}
selectedFileItem.value = tab.fileItem
// 更新面包屑和文件列表到文件所在目录
const dir = getParentPath(tab.fileItem.path)
if (dir && dir !== filePath.value) {
filePath.value = dir
loadDirectory(dir).catch(e => Message.error(`目录加载失败: ${e}`))
}
if (tab.loaded) {
restoreTabState(tab)
} else {