From 908ef635faa9cb4adb24ce11fc5a276873e00b2c Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 6 Nov 2022 13:30:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=97=E8=A1=A8=E6=AD=8C?= =?UTF-8?q?=E6=9B=B2=E7=A7=BB=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worker/dbService/modules/list/index.ts | 55 +++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/src/main/worker/dbService/modules/list/index.ts b/src/main/worker/dbService/modules/list/index.ts index 301864d3..94197857 100644 --- a/src/main/worker/dbService/modules/list/index.ts +++ b/src/main/worker/dbService/modules/list/index.ts @@ -240,50 +240,37 @@ export const musicsRemove = (listId: string, ids: string[]) => { * @param addMusicLocationType 添加在到列表的位置 */ export const musicsMove = (fromId: string, toId: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.AddMusicLocationType) => { - const ids = musicInfos.map(musicInfo => musicInfo.id) + let fromList = getListMusics(fromId) let toList = getListMusics(toId) + + const ids = musicInfos.map(musicInfo => musicInfo.id) + + const map = new Map() + for (const item of toList) map.set(item.id, item) + musicInfos = musicInfos.filter(item => { + if (map.has(item.id)) return false + map.set(item.id, item) + return true + }) + switch (addMusicLocationType) { case 'top': moveMusicInfoAndRefreshOrder(fromId, ids, toId, toDBMusicInfo(musicInfos, toId), toDBMusicInfo(toList, toId, musicInfos.length)) + toList.unshift(...musicInfos) break case 'bottom': default: moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length)) + toList.push(...musicInfos) break } - musicsRemove(fromId, ids) - musicsAdd(toId, musicInfos, addMusicLocationType) - // let fromList = getListMusics(fromId) - // let toList = getListMusics(toId) - - // const ids = musicInfos.map(musicInfo => musicInfo.id) - - // const map = new Map() - // for (const item of toList) map.set(item.id, item) - // musicInfos = musicInfos.filter(item => { - // if (map.has(item.id)) return false - // map.set(item.id, item) - // return true - // }) - - // switch (addMusicLocationType) { - // case 'top': - // moveMusicInfoAndRefreshOrder(fromId, ids, toId, toDBMusicInfo(musicInfos, toId), toDBMusicInfo(toList, toId, musicInfos.length)) - // toList.unshift(...musicInfos) - // break - // case 'bottom': - // default: - // moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length)) - // toList.push(...musicInfos) - // break - // } - // for (let i = fromList.length - 1; i > -1; i--) { - // const item = fromList[i] - // const index = ids.indexOf(item.id) - // if (index < 0) continue - // ids.splice(index, 1) - // fromList.splice(i, 1) - // } + for (let i = fromList.length - 1; i > -1; i--) { + const item = fromList[i] + const index = ids.indexOf(item.id) + if (index < 0) continue + ids.splice(index, 1) + fromList.splice(i, 1) + } } /**