mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-15 07:20:49 +08:00
✨ feat: 修复未登录 收藏问题
This commit is contained in:
@@ -105,7 +105,7 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
async addToFavorite(state: State, songId: number) {
|
async addToFavorite(state: State, songId: number) {
|
||||||
try {
|
try {
|
||||||
await likeSong(songId, true);
|
state.user && localStorage.getItem('token') && await likeSong(songId, true);
|
||||||
if (!state.favoriteList.includes(songId)) {
|
if (!state.favoriteList.includes(songId)) {
|
||||||
state.favoriteList = [songId, ...state.favoriteList];
|
state.favoriteList = [songId, ...state.favoriteList];
|
||||||
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
|
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
|
||||||
@@ -116,7 +116,7 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
async removeFromFavorite(state: State, songId: number) {
|
async removeFromFavorite(state: State, songId: number) {
|
||||||
try {
|
try {
|
||||||
await likeSong(songId, false);
|
state.user && localStorage.getItem('token') && await likeSong(songId, false);
|
||||||
state.favoriteList = state.favoriteList.filter((id) => id !== songId);
|
state.favoriteList = state.favoriteList.filter((id) => id !== songId);
|
||||||
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
|
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user