diff --git a/src/renderer/store/modules/localMusic.ts b/src/renderer/store/modules/localMusic.ts index 2e1d276..8ee535e 100644 --- a/src/renderer/store/modules/localMusic.ts +++ b/src/renderer/store/modules/localMusic.ts @@ -125,6 +125,9 @@ export const useLocalMusicStore = defineStore( cachedMap.set(entry.filePath, entry); } + // 磁盘上实际存在的文件路径集合(扫描时收集) + const diskFilePaths = new Set(); + // 遍历每个文件夹进行扫描 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) { diff --git a/src/renderer/views/local-music/index.vue b/src/renderer/views/local-music/index.vue index 60afc74..b443f23 100644 --- a/src/renderer/views/local-music/index.vue +++ b/src/renderer/views/local-music/index.vue @@ -1,172 +1,171 @@