修复列表歌曲移动问题

pull/1050/head
lyswhut 2022-11-06 13:30:59 +08:00
parent 6b2cf5df2f
commit 908ef635fa
1 changed files with 21 additions and 34 deletions

View File

@ -240,50 +240,37 @@ export const musicsRemove = (listId: string, ids: string[]) => {
* @param addMusicLocationType * @param addMusicLocationType
*/ */
export const musicsMove = (fromId: string, toId: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.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) let toList = getListMusics(toId)
const ids = musicInfos.map(musicInfo => musicInfo.id)
const map = new Map<string, LX.Music.MusicInfo>()
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) { switch (addMusicLocationType) {
case 'top': case 'top':
moveMusicInfoAndRefreshOrder(fromId, ids, toId, toDBMusicInfo(musicInfos, toId), toDBMusicInfo(toList, toId, musicInfos.length)) moveMusicInfoAndRefreshOrder(fromId, ids, toId, toDBMusicInfo(musicInfos, toId), toDBMusicInfo(toList, toId, musicInfos.length))
toList.unshift(...musicInfos)
break break
case 'bottom': case 'bottom':
default: default:
moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length)) moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length))
toList.push(...musicInfos)
break break
} }
musicsRemove(fromId, ids) for (let i = fromList.length - 1; i > -1; i--) {
musicsAdd(toId, musicInfos, addMusicLocationType) const item = fromList[i]
// let fromList = getListMusics(fromId) const index = ids.indexOf(item.id)
// let toList = getListMusics(toId) if (index < 0) continue
ids.splice(index, 1)
// const ids = musicInfos.map(musicInfo => musicInfo.id) fromList.splice(i, 1)
}
// const map = new Map<string, LX.Music.MusicInfo>()
// 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)
// }
} }
/** /**