mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-15 15:30:49 +08:00
✨ feat: 歌曲右键 添加下一首播放功能
This commit is contained in:
@@ -133,6 +133,11 @@ const dropdownY = ref(0);
|
||||
const isDownloading = ref(false);
|
||||
|
||||
const dropdownOptions = computed<MenuOption[]>(() => [
|
||||
{
|
||||
label: '下一首播放',
|
||||
key: 'playNext',
|
||||
icon: () => h('i', { class: 'iconfont ri-play-list-2-line' })
|
||||
},
|
||||
{
|
||||
label: isDownloading.value ? '下载中...' : `下载 ${props.item.name}`,
|
||||
key: 'download',
|
||||
@@ -152,6 +157,8 @@ const handleSelect = (key: string | number) => {
|
||||
showDropdown.value = false;
|
||||
if (key === 'download') {
|
||||
downloadMusic();
|
||||
} else if (key === 'playNext') {
|
||||
handlePlayNext();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -281,6 +288,12 @@ const handleArtistClick = (id: number) => {
|
||||
const artists = computed(() => {
|
||||
return (props.item.ar || props.item.song?.artists)?.slice(0, 4) || [];
|
||||
});
|
||||
|
||||
// 添加到下一首播放
|
||||
const handlePlayNext = () => {
|
||||
store.commit('addToNextPlay', props.item);
|
||||
message.success('已添加到下一首播放');
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -4,7 +4,6 @@ import setData from '@/../main/set.json';
|
||||
import { getLikedList, likeSong } from '@/api/music';
|
||||
import { useMusicListHook } from '@/hooks/MusicListHook';
|
||||
import homeRouter from '@/router/home';
|
||||
import { audioService } from '@/services/audioService';
|
||||
import type { SongResult } from '@/type/music';
|
||||
import { isElectron } from '@/utils';
|
||||
import { applyTheme, getCurrentTheme, ThemeType } from '@/utils/theme';
|
||||
@@ -153,6 +152,27 @@ const mutations = {
|
||||
async prevPlay(state: State) {
|
||||
await prevPlay(state);
|
||||
},
|
||||
// 添加到下一首播放
|
||||
addToNextPlay(state: State, song: SongResult) {
|
||||
const playList = [...state.playList];
|
||||
const currentIndex = state.playListIndex;
|
||||
|
||||
// 检查歌曲是否已经在播放列表中
|
||||
const existingIndex = playList.findIndex((item) => item.id === song.id);
|
||||
if (existingIndex !== -1) {
|
||||
// 如果歌曲已经在列表中,将其移动到当前播放歌曲的下一个位置
|
||||
playList.splice(existingIndex, 1);
|
||||
}
|
||||
|
||||
// 在当前播放歌曲后插入新歌曲
|
||||
playList.splice(currentIndex + 1, 0, song);
|
||||
|
||||
// 更新播放列表
|
||||
state.playList = playList;
|
||||
state.playListIndex = playList.findIndex((item) => item.id === state.playMusic.id);
|
||||
localStorage.setItem('playList', JSON.stringify(playList));
|
||||
localStorage.setItem('playListIndex', state.playListIndex.toString());
|
||||
},
|
||||
setSetData(state: State, setData: any) {
|
||||
state.setData = setData;
|
||||
if (isElectron) {
|
||||
|
||||
Reference in New Issue
Block a user