2021-07-21 15:01:39 +08:00
|
|
|
<template>
|
2023-12-11 16:22:05 +08:00
|
|
|
<div class="recommend-music">
|
|
|
|
|
<div class="title" :class="setAnimationClass('animate__fadeInLeft')">
|
|
|
|
|
本周最热音乐
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="recommend-music-list"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInUp')"
|
|
|
|
|
v-show="recommendMusic?.result"
|
|
|
|
|
>
|
|
|
|
|
<!-- 推荐音乐列表 -->
|
|
|
|
|
<template v-for="(item, index) in recommendMusic?.result" :key="item.id">
|
2021-07-21 15:01:39 +08:00
|
|
|
<div
|
2023-12-11 16:22:05 +08:00
|
|
|
:class="setAnimationClass('animate__bounceInUp')"
|
|
|
|
|
:style="setAnimationDelay(index, 100)"
|
2021-07-21 15:01:39 +08:00
|
|
|
>
|
2023-12-11 16:22:05 +08:00
|
|
|
<song-item :item="item" @play="handlePlay" />
|
2021-07-21 15:01:39 +08:00
|
|
|
</div>
|
2023-12-11 16:22:05 +08:00
|
|
|
</template>
|
2021-07-21 15:01:39 +08:00
|
|
|
</div>
|
2023-12-11 16:22:05 +08:00
|
|
|
</div>
|
2021-07-21 15:01:39 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-11 16:22:05 +08:00
|
|
|
import { getRecommendMusic } from '@/api/home'
|
|
|
|
|
import type { IRecommendMusic } from '@/type/music'
|
|
|
|
|
import { setAnimationClass, setAnimationDelay } from '@/utils'
|
|
|
|
|
import SongItem from './common/SongItem.vue'
|
|
|
|
|
import { useStore } from 'vuex'
|
|
|
|
|
|
|
|
|
|
const store = useStore();
|
2021-07-21 15:01:39 +08:00
|
|
|
// 推荐歌曲
|
2023-12-11 16:22:05 +08:00
|
|
|
const recommendMusic = ref<IRecommendMusic>()
|
2021-07-21 15:01:39 +08:00
|
|
|
|
|
|
|
|
// 加载推荐歌曲
|
|
|
|
|
const loadRecommendMusic = async () => {
|
2023-12-11 16:22:05 +08:00
|
|
|
const { data } = await getRecommendMusic({ limit: 10 })
|
|
|
|
|
recommendMusic.value = data
|
|
|
|
|
}
|
2021-07-21 15:01:39 +08:00
|
|
|
|
|
|
|
|
// 页面初始化
|
|
|
|
|
onMounted(() => {
|
2023-12-11 16:22:05 +08:00
|
|
|
loadRecommendMusic()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handlePlay = (item: any) => {
|
2023-12-27 14:40:22 +08:00
|
|
|
store.commit('setPlayList', recommendMusic.value?.result)
|
2023-12-11 16:22:05 +08:00
|
|
|
}
|
2021-07-21 15:01:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.title {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply text-lg font-bold mb-4;
|
2021-07-21 15:01:39 +08:00
|
|
|
}
|
|
|
|
|
.recommend-music {
|
2023-12-11 16:22:05 +08:00
|
|
|
@apply flex-auto;
|
|
|
|
|
// width: 530px;
|
|
|
|
|
.text-ellipsis {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
&-list {
|
|
|
|
|
@apply rounded-3xl p-2 w-full border border-gray-700;
|
|
|
|
|
background-color: #0d0d0d;
|
|
|
|
|
}
|
2021-07-21 15:01:39 +08:00
|
|
|
}
|
2023-12-11 16:22:05 +08:00
|
|
|
</style>
|