mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 10:27:30 +08:00
refactor(player): 提取播放栏共享逻辑为 composable
- 新增 useVolumeControl:统一音量管理(volumeSlider、mute、滚轮调节) - 新增 useFavorite:收藏状态与切换 - 新增 usePlaybackControl:播放/暂停、上/下一首 - PlayBar、MiniPlayBar、SimplePlayBar、MobilePlayBar 使用新 composable - 修复音量存储不一致:MiniPlayBar/SimplePlayBar 原先绕过 playerStore 直接操作 localStorage
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { playMusic } from '@/hooks/MusicHook';
|
||||
import { usePlayerStore } from '@/store/modules/player';
|
||||
|
||||
/**
|
||||
* 播放控制 composable(播放/暂停、上一首、下一首)
|
||||
*/
|
||||
export function usePlaybackControl() {
|
||||
const playerStore = usePlayerStore();
|
||||
|
||||
/** 是否正在播放 */
|
||||
const isPlaying = computed(() => playerStore.isPlay);
|
||||
|
||||
/** 播放/暂停切换 */
|
||||
const playMusicEvent = async () => {
|
||||
try {
|
||||
await playerStore.setPlay({ ...playMusic.value });
|
||||
} catch (error) {
|
||||
console.error('播放出错:', error);
|
||||
playerStore.nextPlay();
|
||||
}
|
||||
};
|
||||
|
||||
/** 下一首 */
|
||||
const handleNext = () => {
|
||||
playerStore.nextPlay();
|
||||
};
|
||||
|
||||
/** 上一首 */
|
||||
const handlePrev = () => {
|
||||
playerStore.prevPlay();
|
||||
};
|
||||
|
||||
return {
|
||||
isPlaying,
|
||||
playMusicEvent,
|
||||
handleNext,
|
||||
handlePrev
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user