修复列表歌曲移动问题

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
*/
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<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
}
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<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)
// }
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)
}
}
/**