feat: 添加搜藏功能 与页面

This commit is contained in:
alger
2024-12-09 21:55:08 +08:00
parent 1e60fa9a95
commit 721d2a9704
7 changed files with 280 additions and 14 deletions
+12
View File
@@ -27,6 +27,7 @@ interface State {
isMobile: boolean;
searchValue: string;
searchType: number;
favoriteList: number[];
}
const state: State = {
@@ -43,6 +44,7 @@ const state: State = {
isMobile: false,
searchValue: '',
searchType: 1,
favoriteList: localStorage.getItem('favoriteList') ? JSON.parse(localStorage.getItem('favoriteList') || '[]') : [],
};
const { handlePlayMusic, nextPlay, prevPlay } = useMusicListHook();
@@ -79,6 +81,16 @@ const mutations = {
localStorage.setItem('appSettings', JSON.stringify(setData));
}
},
addToFavorite(state: State, songId: number) {
if (!state.favoriteList.includes(songId)) {
state.favoriteList = [songId, ...state.favoriteList];
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
}
},
removeFromFavorite(state: State, songId: number) {
state.favoriteList = state.favoriteList.filter((id) => id !== songId);
localStorage.setItem('favoriteList', JSON.stringify(state.favoriteList));
},
};
const actions = {