fix(local-music): 扫描自动清理已删除文件,修复双滚动条

- scanFolders() 扫描时收集磁盘文件路径,完成后自动移除 IndexedDB 中已删除的条目
- 移除外层 n-scrollbar,改用 flex 布局,n-virtual-list 作为唯一滚动容器
This commit is contained in:
alger
2026-03-27 23:00:54 +08:00
parent bc46024499
commit c28368f783
2 changed files with 164 additions and 150 deletions
+15
View File
@@ -125,6 +125,9 @@ export const useLocalMusicStore = defineStore(
cachedMap.set(entry.filePath, entry);
}
// 磁盘上实际存在的文件路径集合(扫描时收集)
const diskFilePaths = new Set<string>();
// 遍历每个文件夹进行扫描
for (const folderPath of folderPaths.value) {
try {
@@ -141,6 +144,11 @@ export const useLocalMusicStore = defineStore(
const { files } = result;
scanProgress.value += files.length;
// 记录磁盘上存在的文件
for (const file of files) {
diskFilePaths.add(file.path);
}
// 2. 增量扫描:基于修改时间筛选需重新解析的文件
const parseTargets: string[] = [];
for (const file of files) {
@@ -168,6 +176,13 @@ export const useLocalMusicStore = defineStore(
}
}
// 4. 清理已删除文件:从 IndexedDB 移除磁盘上不存在的条目
for (const [filePath, entry] of cachedMap) {
if (!diskFilePaths.has(filePath)) {
await localDB.deleteData(LOCAL_MUSIC_STORE, entry.id);
}
}
// 5. 从 IndexedDB 重新加载完整列表
musicList.value = await localDB.getAllData(LOCAL_MUSIC_STORE);
} catch (error) {