fix: 修复在某些情况下移动歌曲时可能导致保存的顺序不对的问题(#2842)

This commit is contained in:
lyswhut
2026-07-02 12:42:54 +08:00
parent f0776becff
commit d5b1b3fd5f
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -10,4 +10,4 @@
- 修复某些情况下开放 API 获取到的音量为 0 的问题 (#2790)
- 修复 mg 图片、歌词获取
- 修复某些 tx 歌单打开失败的问题 (#1060, @ght-000)
- 修复在某些情况下添加歌曲时可能导致保存的歌曲顺序不对的问题(#2842)
- 修复在某些情况下添加、移动歌曲时可能导致保存的歌曲顺序不对的问题(#2842)
@@ -275,11 +275,15 @@ export const musicsMove = (fromId: string, toId: string, musicInfos: LX.Music.Mu
arrUnshift(toList, musicInfos)
break
case 'bottom':
default:
moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length))
default:{
// 如果是添加到最后,那么取最后一个歌曲的原始位置 + 1 作为新歌曲的原始位置,否则新歌曲的原始位置为 position
// 因为原始 pos 可能比 targetList.length 大,所以不能直接用 targetList.length 作为新歌曲的原始位置
const order = toList.length ? (getMusicInfoOrder(toId, toList.at(-1)!.id)?.order ?? toList.length) + 1 : 0
moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, order))
arrPush(toList, musicInfos)
break
}
}
listSet = new Set<string>(ids)
musicLists.set(fromId, fromList.filter(mInfo => !listSet.has(mInfo.id)))