From ecd7a56df03e6285c553f435ae8764f532b8429b Mon Sep 17 00:00:00 2001 From: alger Date: Mon, 1 Jan 2024 00:06:52 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=93?= =?UTF-8?q?=E8=BE=91=E5=88=97=E8=A1=A8=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/list.ts | 79 +++++++++++++++------------- src/components/MusicList.vue | 9 ++-- src/components/RecommendAlbum.vue | 17 ++++++ src/components/common/SearchItem.vue | 22 +++++++- src/components/common/SongItem.vue | 1 + src/hooks/MusicHook.ts | 2 +- src/store/index.ts | 2 +- src/views/list/index.vue | 2 +- src/views/search/index.vue | 1 - src/views/user/index.vue | 2 +- 10 files changed, 90 insertions(+), 47 deletions(-) diff --git a/src/api/list.ts b/src/api/list.ts index 096cbbe..bceb4fb 100644 --- a/src/api/list.ts +++ b/src/api/list.ts @@ -1,37 +1,42 @@ -import request from "@/utils/request"; -import { IList } from "@/type/list"; -import type { IListDetail } from "@/type/listDetail"; - -interface IListByTagParams { - tag: string; - before: number; - limit: number; -} - -interface IListByCatParams { - cat: string; - offset: number; - limit: number; -} - -// 根据tag 获取歌单列表 -export function getListByTag(params: IListByTagParams) { - return request.get("/top/playlist/highquality", { params: params }); -} - -// 根据cat 获取歌单列表 -export function getListByCat(params: IListByCatParams) { - return request.get("/top/playlist", { - params: params, - }); -} - -// 获取推荐歌单 -export function getRecommendList(limit: number = 30) { - return request.get("/personalized", { params: { limit } }); -} - -// 获取歌单详情 -export function getListDetail(id: number | string) { - return request.get("/playlist/detail", { params: { id } }); -} +import request from "@/utils/request"; +import { IList } from "@/type/list"; +import type { IListDetail } from "@/type/listDetail"; + +interface IListByTagParams { + tag: string; + before: number; + limit: number; +} + +interface IListByCatParams { + cat: string; + offset: number; + limit: number; +} + +// 根据tag 获取歌单列表 +export function getListByTag(params: IListByTagParams) { + return request.get("/top/playlist/highquality", { params: params }); +} + +// 根据cat 获取歌单列表 +export function getListByCat(params: IListByCatParams) { + return request.get("/top/playlist", { + params: params, + }); +} + +// 获取推荐歌单 +export function getRecommendList(limit: number = 30) { + return request.get("/personalized", { params: { limit } }); +} + +// 获取歌单详情 +export function getListDetail(id: number | string) { + return request.get("/playlist/detail", { params: { id } }); +} + +// 获取专辑内容 +export function getAlbum(id: number | string) { + return request.get("/album", { params: { id } }); +} \ No newline at end of file diff --git a/src/components/MusicList.vue b/src/components/MusicList.vue index 08eb5ea..db438b6 100644 --- a/src/components/MusicList.vue +++ b/src/components/MusicList.vue @@ -2,11 +2,11 @@
-
{{ musicList?.name }}
+
{{ name }}
-
@@ -28,7 +28,8 @@ const store = useStore() const props = defineProps<{ show: boolean; - musicList: Playlist; + name: string; + songList: any[] }>() const emit = defineEmits(['update:show']) @@ -45,7 +46,7 @@ const formatDetail = computed(() => (detail: any) => { }) const handlePlay = (item: any) => { - const tracks = props.musicList?.tracks || [] + const tracks = props.songList || [] const musicIndex = (tracks.findIndex((music: any) => music.id == item.id) || 0) store.commit('setPlayList', tracks) } diff --git a/src/components/RecommendAlbum.vue b/src/components/RecommendAlbum.vue index ef0f189..7362447 100644 --- a/src/components/RecommendAlbum.vue +++ b/src/components/RecommendAlbum.vue @@ -8,6 +8,7 @@ class="recommend-album-list-item" :class="setAnimationClass('animate__backInUp')" :style="setAnimationDelay(index, 100)" + @click="handleClick(item)" >
+
@@ -27,6 +29,7 @@ import { getNewAlbum } from "@/api/home" import { ref, onMounted } from "vue"; import type { IAlbumNew } from "@/type/album" import { setAnimationClass, setAnimationDelay, getImgUrl } from "@/utils"; +import { getAlbum } from "@/api/list"; const albumData = ref() @@ -35,6 +38,20 @@ const loadAlbumList = async () => { albumData.value = data } +const showMusic = ref(false) +const songList = ref([]) +const albumName = ref('') + +const handleClick = async (item:any) => { + albumName.value = item.name + showMusic.value = true + const res = await getAlbum(item.id) + songList.value = res.data.songs.map((song:any)=>{ + song.al.picUrl = song.al.picUrl || item.picUrl + return song + }) +} + onMounted(() => { loadAlbumList() }) diff --git a/src/components/common/SearchItem.vue b/src/components/common/SearchItem.vue index 69035e8..2a9ea6b 100644 --- a/src/components/common/SearchItem.vue +++ b/src/components/common/SearchItem.vue @@ -1,5 +1,5 @@