2021-07-21 15:01:39 +08:00
|
|
|
<template>
|
2023-12-11 16:22:05 +08:00
|
|
|
<!-- 展开全屏 -->
|
2024-09-14 18:22:56 +08:00
|
|
|
<music-full
|
|
|
|
|
ref="MusicFullRef"
|
|
|
|
|
v-model:music-full="musicFullVisible"
|
|
|
|
|
:audio="audio.value as HTMLAudioElement"
|
|
|
|
|
:background="background"
|
|
|
|
|
/>
|
2023-12-11 16:22:05 +08:00
|
|
|
<!-- 底部播放栏 -->
|
2024-09-12 15:00:00 +08:00
|
|
|
<div
|
|
|
|
|
class="music-play-bar"
|
2024-09-12 16:44:42 +08:00
|
|
|
:class="setAnimationClass('animate__bounceInUp') + ' ' + (musicFullVisible ? 'play-bar-opcity' : '')"
|
2024-09-12 15:00:00 +08:00
|
|
|
>
|
2023-12-15 14:24:58 +08:00
|
|
|
<n-image
|
2023-12-17 14:48:21 +08:00
|
|
|
:src="getImgUrl(playMusic?.picUrl, '300y300')"
|
2023-12-16 13:42:52 +08:00
|
|
|
class="play-bar-img"
|
|
|
|
|
lazy
|
|
|
|
|
preview-disabled
|
|
|
|
|
@click="setMusicFull"
|
|
|
|
|
/>
|
2023-12-11 16:22:05 +08:00
|
|
|
<div class="music-content">
|
|
|
|
|
<div class="music-content-title">
|
2023-12-16 13:42:52 +08:00
|
|
|
<n-ellipsis class="text-ellipsis" line-clamp="1">
|
2023-12-17 14:48:21 +08:00
|
|
|
{{ playMusic.name }}
|
2023-12-16 13:42:52 +08:00
|
|
|
</n-ellipsis>
|
2023-12-11 16:22:05 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="music-content-name">
|
|
|
|
|
<n-ellipsis class="text-ellipsis" line-clamp="1">
|
2024-09-13 09:43:05 +08:00
|
|
|
<span v-for="(item, index) in playMusic.song.artists" :key="index">
|
|
|
|
|
{{ item.name }}{{ index < playMusic.song.artists.length - 1 ? ' / ' : '' }}
|
2023-12-16 13:42:52 +08:00
|
|
|
</span>
|
2023-12-11 16:22:05 +08:00
|
|
|
</n-ellipsis>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="music-buttons">
|
2024-05-23 17:12:35 +08:00
|
|
|
<div class="music-buttons-prev" @click="handlePrev">
|
2023-12-11 16:22:05 +08:00
|
|
|
<i class="iconfont icon-prev"></i>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="music-buttons-play" @click="playMusicEvent">
|
|
|
|
|
<i class="iconfont icon" :class="play ? 'icon-stop' : 'icon-play'"></i>
|
|
|
|
|
</div>
|
2024-05-23 17:12:35 +08:00
|
|
|
<div class="music-buttons-next" @click="handleEnded">
|
2023-12-11 16:22:05 +08:00
|
|
|
<i class="iconfont icon-next"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="music-time">
|
|
|
|
|
<div class="time">{{ getNowTime }}</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
<n-slider v-model:value="timeSlider" :step="0.05" :tooltip="false"></n-slider>
|
2023-12-11 16:22:05 +08:00
|
|
|
<div class="time">{{ getAllTime }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="audio-volume">
|
|
|
|
|
<div>
|
|
|
|
|
<i class="iconfont icon-notificationfill"></i>
|
|
|
|
|
</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
<n-slider v-model:value="volumeSlider" :step="0.01" :tooltip="false"></n-slider>
|
2021-07-21 15:01:39 +08:00
|
|
|
</div>
|
2023-12-11 16:22:05 +08:00
|
|
|
<div class="audio-button">
|
2023-12-27 14:39:52 +08:00
|
|
|
<!-- <n-tooltip trigger="hover" :z-index="9999999">
|
2023-12-11 16:22:05 +08:00
|
|
|
<template #trigger>
|
|
|
|
|
<i class="iconfont icon-likefill"></i>
|
|
|
|
|
</template>
|
|
|
|
|
喜欢
|
2023-12-27 14:39:52 +08:00
|
|
|
</n-tooltip> -->
|
|
|
|
|
<!-- <n-tooltip trigger="hover" :z-index="9999999">
|
2023-12-11 16:22:05 +08:00
|
|
|
<template #trigger>
|
|
|
|
|
<i class="iconfont icon-Play" @click="parsingMusic"></i>
|
|
|
|
|
</template>
|
|
|
|
|
解析播放
|
2023-12-20 15:53:33 +08:00
|
|
|
</n-tooltip> -->
|
2024-09-12 16:44:42 +08:00
|
|
|
<n-tooltip v-if="isElectron" class="music-lyric" trigger="hover" :z-index="9999999">
|
2023-12-11 16:22:05 +08:00
|
|
|
<template #trigger>
|
2024-05-16 18:54:30 +08:00
|
|
|
<i class="iconfont ri-netease-cloud-music-line" @click="openLyric"></i>
|
2023-12-11 16:22:05 +08:00
|
|
|
</template>
|
|
|
|
|
歌词
|
2024-05-16 18:54:30 +08:00
|
|
|
</n-tooltip>
|
2023-12-27 14:39:52 +08:00
|
|
|
<n-popover trigger="click" :z-index="99999999" content-class="music-play" raw :show-arrow="false" :delay="200">
|
|
|
|
|
<template #trigger>
|
|
|
|
|
<n-tooltip trigger="manual" :z-index="9999999">
|
|
|
|
|
<template #trigger>
|
|
|
|
|
<i class="iconfont icon-list"></i>
|
|
|
|
|
</template>
|
|
|
|
|
播放列表
|
|
|
|
|
</n-tooltip>
|
|
|
|
|
</template>
|
|
|
|
|
<div class="music-play-list">
|
|
|
|
|
<div class="music-play-list-back"></div>
|
2024-09-13 09:08:57 +08:00
|
|
|
<n-virtual-list :item-size="57" item-resizable :items="playList">
|
|
|
|
|
<template #default="{ item }">
|
|
|
|
|
<div class="music-play-list-content">
|
|
|
|
|
<song-item :key="item.id" :item="item" mini></song-item>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2024-09-12 16:44:42 +08:00
|
|
|
</n-virtual-list>
|
2023-12-27 14:39:52 +08:00
|
|
|
</div>
|
|
|
|
|
</n-popover>
|
2023-12-11 16:22:05 +08:00
|
|
|
</div>
|
|
|
|
|
<!-- 播放音乐 -->
|
|
|
|
|
</div>
|
2021-07-21 15:01:39 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-05-16 18:54:30 +08:00
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
|
|
|
|
|
import SongItem from '@/components/common/SongItem.vue';
|
2024-09-12 16:44:42 +08:00
|
|
|
import { allTime, isElectron, loadLrc, nowTime, openLyric, sendLyricToWin } from '@/hooks/MusicHook';
|
2024-09-13 09:43:05 +08:00
|
|
|
import type { SongResult } from '@/type/music';
|
2024-05-16 18:54:30 +08:00
|
|
|
import { getImgUrl, secondToMinute, setAnimationClass } from '@/utils';
|
2024-09-14 18:22:56 +08:00
|
|
|
import { getImageLinearBackground } from '@/utils/linearColor';
|
2024-05-16 18:54:30 +08:00
|
|
|
|
|
|
|
|
import MusicFull from './MusicFull.vue';
|
|
|
|
|
|
|
|
|
|
const store = useStore();
|
2021-07-21 17:45:21 +08:00
|
|
|
|
2021-07-21 22:29:44 +08:00
|
|
|
// 播放的音乐信息
|
2024-09-13 09:43:05 +08:00
|
|
|
const playMusic = computed(() => store.state.playMusic as SongResult);
|
2021-07-21 22:29:44 +08:00
|
|
|
// 是否播放
|
2024-05-16 18:54:30 +08:00
|
|
|
const play = computed(() => store.state.play as boolean);
|
2023-12-21 18:09:12 +08:00
|
|
|
|
2024-09-13 09:43:05 +08:00
|
|
|
const playList = computed(() => store.state.playList as SongResult[]);
|
2023-12-27 14:39:52 +08:00
|
|
|
|
2023-12-21 18:09:12 +08:00
|
|
|
const audio = {
|
2024-05-16 18:54:30 +08:00
|
|
|
value: document.querySelector('#MusicAudio') as HTMLAudioElement,
|
|
|
|
|
};
|
2024-09-14 18:22:56 +08:00
|
|
|
const background = ref('#000');
|
2023-12-21 18:09:12 +08:00
|
|
|
|
2023-12-11 16:22:05 +08:00
|
|
|
watch(
|
2024-09-14 18:22:56 +08:00
|
|
|
() => store.state.playMusic,
|
|
|
|
|
async () => {
|
2024-05-16 18:54:30 +08:00
|
|
|
loadLrc(playMusic.value.id);
|
2024-09-18 15:11:20 +08:00
|
|
|
background.value = playMusic.value.backgroundColor as string;
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
2024-09-14 18:22:56 +08:00
|
|
|
{ immediate: true, deep: true },
|
2024-05-16 18:54:30 +08:00
|
|
|
);
|
2023-12-17 14:48:21 +08:00
|
|
|
|
|
|
|
|
const audioPlay = () => {
|
|
|
|
|
if (audio.value) {
|
2024-05-16 18:54:30 +08:00
|
|
|
audio.value.play();
|
2023-12-17 14:48:21 +08:00
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2023-12-16 13:42:52 +08:00
|
|
|
|
2021-07-21 22:29:44 +08:00
|
|
|
// 计算属性 获取当前播放时间的进度
|
|
|
|
|
const timeSlider = computed({
|
2023-12-11 16:22:05 +08:00
|
|
|
get: () => (nowTime.value / allTime.value) * 100,
|
|
|
|
|
set: (value) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
if (!audio.value) return;
|
|
|
|
|
audio.value.currentTime = (value * allTime.value) / 100;
|
|
|
|
|
audioPlay();
|
|
|
|
|
store.commit('setPlayMusic', true);
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
2024-05-16 18:54:30 +08:00
|
|
|
});
|
2021-07-22 11:32:38 +08:00
|
|
|
|
|
|
|
|
// 音量条
|
2024-05-16 18:54:30 +08:00
|
|
|
const audioVolume = ref(1);
|
2021-07-22 11:32:38 +08:00
|
|
|
const volumeSlider = computed({
|
2023-12-11 16:22:05 +08:00
|
|
|
get: () => audioVolume.value * 100,
|
|
|
|
|
set: (value) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
if (!audio.value) return;
|
|
|
|
|
audio.value.volume = value / 100;
|
2023-12-11 16:22:05 +08:00
|
|
|
},
|
2024-05-16 18:54:30 +08:00
|
|
|
});
|
2021-07-21 22:29:44 +08:00
|
|
|
// 获取当前播放时间
|
|
|
|
|
const getNowTime = computed(() => {
|
2024-05-16 18:54:30 +08:00
|
|
|
return secondToMinute(nowTime.value);
|
|
|
|
|
});
|
2021-07-21 15:01:39 +08:00
|
|
|
|
2021-07-21 22:29:44 +08:00
|
|
|
// 获取总时间
|
|
|
|
|
const getAllTime = computed(() => {
|
2024-05-16 18:54:30 +08:00
|
|
|
return secondToMinute(allTime.value);
|
|
|
|
|
});
|
2021-09-28 22:40:44 +08:00
|
|
|
|
2021-07-21 22:29:44 +08:00
|
|
|
// 监听音乐播放 获取时间
|
2023-12-17 14:48:21 +08:00
|
|
|
const onAudio = () => {
|
2024-05-16 18:54:30 +08:00
|
|
|
if (audio.value) {
|
|
|
|
|
audio.value.removeEventListener('timeupdate', handleGetAudioTime);
|
|
|
|
|
audio.value.removeEventListener('ended', handleEnded);
|
|
|
|
|
audio.value.addEventListener('timeupdate', handleGetAudioTime);
|
|
|
|
|
audio.value.addEventListener('ended', handleEnded);
|
2023-12-21 11:26:03 +08:00
|
|
|
// 监听音乐播放暂停
|
|
|
|
|
audio.value.addEventListener('pause', () => {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('setPlayMusic', false);
|
|
|
|
|
});
|
2023-12-21 11:26:03 +08:00
|
|
|
audio.value.addEventListener('play', () => {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('setPlayMusic', true);
|
|
|
|
|
});
|
2023-12-17 14:48:21 +08:00
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2021-09-28 22:40:44 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
onAudio();
|
2023-12-27 21:05:25 +08:00
|
|
|
|
2023-12-11 16:22:05 +08:00
|
|
|
function handleEnded() {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('nextPlay');
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
2023-12-16 13:42:52 +08:00
|
|
|
function handlePrev() {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('prevPlay');
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
const MusicFullRef = ref<any>(null);
|
2023-12-17 14:48:21 +08:00
|
|
|
|
2024-05-21 11:01:23 +08:00
|
|
|
function handleGetAudioTime(this: HTMLAudioElement) {
|
2023-12-11 16:22:05 +08:00
|
|
|
// 监听音频播放的实时时间事件
|
2024-05-16 18:54:30 +08:00
|
|
|
const audio = this as HTMLAudioElement;
|
2023-12-11 16:22:05 +08:00
|
|
|
// 获取当前播放时间
|
2024-05-16 18:54:30 +08:00
|
|
|
nowTime.value = Math.floor(audio.currentTime);
|
2023-12-11 16:22:05 +08:00
|
|
|
// 获取总时间
|
2024-05-16 18:54:30 +08:00
|
|
|
allTime.value = audio.duration;
|
2023-12-11 16:22:05 +08:00
|
|
|
// 获取音量
|
2024-05-16 18:54:30 +08:00
|
|
|
audioVolume.value = audio.volume;
|
|
|
|
|
sendLyricToWin(store.state.isPlay);
|
2024-09-12 16:44:42 +08:00
|
|
|
if (musicFullVisible.value) {
|
|
|
|
|
MusicFullRef.value?.lrcScroll();
|
|
|
|
|
}
|
2021-07-21 22:29:44 +08:00
|
|
|
}
|
2021-07-21 17:45:21 +08:00
|
|
|
|
2021-07-21 22:29:44 +08:00
|
|
|
// 播放暂停按钮事件
|
2021-07-21 17:45:21 +08:00
|
|
|
const playMusicEvent = async () => {
|
2023-12-11 16:22:05 +08:00
|
|
|
if (play.value) {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('setPlayMusic', false);
|
2023-12-11 16:22:05 +08:00
|
|
|
} else {
|
2024-05-16 18:54:30 +08:00
|
|
|
store.commit('setPlayMusic', true);
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2021-07-21 15:01:39 +08:00
|
|
|
|
2024-09-12 16:44:42 +08:00
|
|
|
const musicFullVisible = ref(false);
|
2021-07-25 15:08:02 +08:00
|
|
|
|
|
|
|
|
// 设置musicFull
|
|
|
|
|
const setMusicFull = () => {
|
2024-09-12 16:44:42 +08:00
|
|
|
musicFullVisible.value = !musicFullVisible.value;
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2021-07-21 15:01:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-07-21 17:45:21 +08:00
|
|
|
.text-ellipsis {
|
2023-12-11 16:22:05 +08:00
|
|
|
width: 100%;
|
2021-07-21 17:45:21 +08:00
|
|
|
}
|
|
|
|
|
|
2021-07-21 15:01:39 +08:00
|
|
|
.music-play-bar {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply h-20 w-full absolute bottom-0 left-0 flex items-center rounded-t-2xl overflow-hidden box-border px-6 py-2;
|
2023-12-27 14:39:52 +08:00
|
|
|
z-index: 9999;
|
2024-01-02 22:19:39 +08:00
|
|
|
box-shadow: 0px 0px 10px 2px rgba(203, 203, 203, 0.034);
|
2024-09-12 15:00:00 +08:00
|
|
|
background-color: #212121;
|
2024-05-16 18:54:30 +08:00
|
|
|
animation-duration: 0.5s !important;
|
|
|
|
|
.music-content {
|
2023-12-21 11:26:03 +08:00
|
|
|
width: 140px;
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply ml-4;
|
|
|
|
|
|
|
|
|
|
&-title {
|
|
|
|
|
@apply text-base text-white;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-name {
|
|
|
|
|
@apply text-xs mt-1;
|
|
|
|
|
@apply text-gray-400;
|
2021-07-25 15:08:02 +08:00
|
|
|
}
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
2021-07-21 15:01:39 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-12 15:00:00 +08:00
|
|
|
.play-bar-opcity {
|
|
|
|
|
background-color: rgba(0, 0, 0, 0.218);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 15:01:39 +08:00
|
|
|
.play-bar-img {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply w-14 h-14 rounded-2xl;
|
2021-07-21 15:01:39 +08:00
|
|
|
}
|
|
|
|
|
|
2021-07-21 17:45:21 +08:00
|
|
|
.music-buttons {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply mx-6;
|
|
|
|
|
|
|
|
|
|
.iconfont {
|
|
|
|
|
@apply text-2xl hover:text-green-500 transition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
|
@apply text-xl hover:text-white;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@apply flex items-center;
|
|
|
|
|
|
2023-12-16 13:42:52 +08:00
|
|
|
> div {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply cursor-pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-play {
|
|
|
|
|
background: #383838;
|
2024-09-14 18:22:56 +08:00
|
|
|
@apply flex justify-center items-center w-12 h-12 rounded-full mx-4 hover:bg-green-500 transition bg-opacity-40;
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
2021-07-21 17:45:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.music-time {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply flex flex-1 items-center;
|
|
|
|
|
|
|
|
|
|
.time {
|
|
|
|
|
@apply mx-4 mt-1;
|
|
|
|
|
}
|
2021-07-22 11:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.audio-volume {
|
2023-12-11 16:22:05 +08:00
|
|
|
width: 140px;
|
|
|
|
|
@apply flex items-center mx-4;
|
|
|
|
|
|
|
|
|
|
.iconfont {
|
|
|
|
|
@apply text-2xl hover:text-green-500 transition cursor-pointer mr-4;
|
|
|
|
|
}
|
2021-07-21 17:45:21 +08:00
|
|
|
}
|
2021-07-22 17:31:43 +08:00
|
|
|
|
|
|
|
|
.audio-button {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply flex items-center mx-4;
|
|
|
|
|
|
|
|
|
|
.iconfont {
|
|
|
|
|
@apply text-2xl hover:text-green-500 transition cursor-pointer m-4;
|
|
|
|
|
}
|
2021-07-22 17:31:43 +08:00
|
|
|
}
|
2023-12-27 14:39:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
.music-play {
|
|
|
|
|
&-list {
|
2023-12-27 14:39:52 +08:00
|
|
|
height: 50vh;
|
2024-09-13 09:08:57 +08:00
|
|
|
width: 300px;
|
|
|
|
|
@apply relative rounded-3xl overflow-hidden py-2;
|
2024-05-16 18:54:30 +08:00
|
|
|
&-back {
|
2023-12-27 14:39:52 +08:00
|
|
|
backdrop-filter: blur(20px);
|
|
|
|
|
@apply absolute top-0 left-0 w-full h-full bg-gray-800 bg-opacity-75;
|
|
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
&-content {
|
2024-09-13 09:08:57 +08:00
|
|
|
@apply mx-2;
|
2023-12-27 14:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-23 17:12:35 +08:00
|
|
|
|
|
|
|
|
.mobile {
|
|
|
|
|
.music-play-bar {
|
|
|
|
|
@apply px-4;
|
|
|
|
|
bottom: 70px;
|
|
|
|
|
}
|
|
|
|
|
.music-time {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.ri-netease-cloud-music-line {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.audio-volume {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.audio-button {
|
|
|
|
|
@apply mx-0;
|
|
|
|
|
}
|
|
|
|
|
.music-buttons {
|
|
|
|
|
@apply m-0;
|
|
|
|
|
&-prev,
|
|
|
|
|
&-next {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
&-play {
|
|
|
|
|
@apply m-0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.music-content {
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-13 09:08:57 +08:00
|
|
|
|
|
|
|
|
:deep(.n-popover) {
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
}
|
2023-12-11 16:22:05 +08:00
|
|
|
</style>
|