mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 14:50:50 +08:00
- 新增 useVolumeControl:统一音量管理(volumeSlider、mute、滚轮调节) - 新增 useFavorite:收藏状态与切换 - 新增 usePlaybackControl:播放/暂停、上/下一首 - PlayBar、MiniPlayBar、SimplePlayBar、MobilePlayBar 使用新 composable - 修复音量存储不一致:MiniPlayBar/SimplePlayBar 原先绕过 playerStore 直接操作 localStorage
36 lines
840 B
TypeScript
36 lines
840 B
TypeScript
import { computed } from 'vue';
|
|
|
|
import { playMusic } from '@/hooks/MusicHook';
|
|
import { usePlayerStore } from '@/store/modules/player';
|
|
|
|
/**
|
|
* 当前歌曲的收藏状态管理 composable
|
|
*/
|
|
export function useFavorite() {
|
|
const playerStore = usePlayerStore();
|
|
|
|
/** 当前歌曲是否已收藏 */
|
|
const isFavorite = computed(() => {
|
|
if (!playMusic?.value?.id) return false;
|
|
return playerStore.favoriteList.includes(playMusic.value.id);
|
|
});
|
|
|
|
/** 切换收藏状态 */
|
|
const toggleFavorite = (e?: Event) => {
|
|
e?.stopPropagation();
|
|
if (!playMusic?.value?.id) return;
|
|
|
|
const favoriteId = playMusic.value.id;
|
|
if (isFavorite.value) {
|
|
playerStore.removeFromFavorite(favoriteId);
|
|
} else {
|
|
playerStore.addToFavorite(favoriteId);
|
|
}
|
|
};
|
|
|
|
return {
|
|
isFavorite,
|
|
toggleFavorite
|
|
};
|
|
}
|