feat: 在播放列表中添加歌曲删除功能,优化播放列表管理逻辑

feat: #92
This commit is contained in:
alger
2025-03-29 23:26:26 +08:00
parent c5e50c9fd5
commit a5f694ea72
2 changed files with 47 additions and 2 deletions
+17 -1
View File
@@ -344,6 +344,21 @@ export const usePlayerStore = defineStore('player', () => {
localStorage.setItem('favoriteList', JSON.stringify(favoriteList.value));
};
const removeFromPlayList = (id: number) => {
const index = playList.value.findIndex((item) => item.id === id);
if (index === -1) return;
// 如果删除的是当前播放的歌曲,先切换到下一首
if (id === playMusic.value.id) {
nextPlay();
}
// 从播放列表中移除,使用不可变的方式
const newPlayList = [...playList.value];
newPlayList.splice(index, 1);
setPlayList(newPlayList);
};
// 初始化播放状态
const initializePlayState = async () => {
const settingStore = useSettingsStore();
@@ -450,6 +465,7 @@ export const usePlayerStore = defineStore('player', () => {
initializePlayState,
initializeFavoriteList,
addToFavorite,
removeFromFavorite
removeFromFavorite,
removeFromPlayList
};
});