From c28368f783fc8fd5def062c4614d5a0f40ef2029 Mon Sep 17 00:00:00 2001 From: alger Date: Fri, 27 Mar 2026 23:00:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(local-music):=20=E6=89=AB=E6=8F=8F=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B8=85=E7=90=86=E5=B7=B2=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=8F=8C=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scanFolders() 扫描时收集磁盘文件路径,完成后自动移除 IndexedDB 中已删除的条目 - 移除外层 n-scrollbar,改用 flex 布局,n-virtual-list 作为唯一滚动容器 --- src/renderer/store/modules/localMusic.ts | 15 ++ src/renderer/views/local-music/index.vue | 299 +++++++++++------------ 2 files changed, 164 insertions(+), 150 deletions(-) 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 @@