mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 06:30:49 +08:00
✨ feat: 添加专辑列表播放
This commit is contained in:
@@ -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<IList>("/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<IListDetail>("/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<IList>("/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<IListDetail>("/playlist/detail", { params: { id } });
|
||||
}
|
||||
|
||||
// 获取专辑内容
|
||||
export function getAlbum(id: number | string) {
|
||||
return request.get("/album", { params: { id } });
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
<n-drawer :show="show" height="70vh" placement="bottom" :drawer-style="{ backgroundColor: 'transparent' }">
|
||||
<div class="music-page">
|
||||
<i class="iconfont icon-icon_error music-close" @click="close"></i>
|
||||
<div class="music-title">{{ musicList?.name }}</div>
|
||||
<div class="music-title">{{ name }}</div>
|
||||
<!-- 歌单歌曲列表 -->
|
||||
<div class="music-list">
|
||||
<n-scrollbar >
|
||||
<div v-for="(item, index) in musicList?.tracks" :key="item.id" :class="setAnimationClass('animate__bounceInUp')"
|
||||
<div v-for="(item, index) in songList" :key="item.id" :class="setAnimationClass('animate__bounceInUp')"
|
||||
:style="setAnimationDelay(index, 100)">
|
||||
<SongItem :item="formatDetail(item)" @play="handlePlay" />
|
||||
</div>
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
class="recommend-album-list-item"
|
||||
:class="setAnimationClass('animate__backInUp')"
|
||||
:style="setAnimationDelay(index, 100)"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<n-image
|
||||
class="recommend-album-list-item-img"
|
||||
@@ -19,6 +20,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<MusicList v-model:show="showMusic" :name="albumName" :song-list="songList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -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<IAlbumNew>()
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="search-item">
|
||||
<div class="search-item" @click="handleClick">
|
||||
<div class="search-item-img">
|
||||
<n-image
|
||||
:src="getImgUrl(item.picUrl, 'album')"
|
||||
@@ -11,20 +11,40 @@
|
||||
<div class="search-item-name">{{ item.name }}</div>
|
||||
<div class="search-item-artist">{{ item.desc}}</div>
|
||||
</div>
|
||||
|
||||
<MusicList v-model:show="showMusic" :name="item.name" :song-list="songList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getImgUrl } from '@/utils'
|
||||
import type {Album} from '@/type/album'
|
||||
import { getAlbum } from '@/api/list';
|
||||
const props = defineProps<{
|
||||
item: {
|
||||
picUrl: string
|
||||
name: string
|
||||
desc: string
|
||||
type: string
|
||||
[key: string]: any
|
||||
}
|
||||
}>()
|
||||
|
||||
const songList = ref([])
|
||||
|
||||
const showMusic = ref(false)
|
||||
|
||||
const handleClick = async () => {
|
||||
showMusic.value = true
|
||||
if(props.item.type === '专辑'){
|
||||
const res = await getAlbum(props.item.id)
|
||||
songList.value = res.data.songs.map((song:any)=>{
|
||||
song.al.picUrl = song.al.picUrl || props.item.picUrl
|
||||
return song
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div class="song-item" :class="{'song-mini': mini}">
|
||||
<n-image
|
||||
v-if="item.picUrl "
|
||||
:src="getImgUrl( item.picUrl, '40y40')"
|
||||
class="song-item-img"
|
||||
lazy
|
||||
|
||||
@@ -57,7 +57,7 @@ const loadLrc = async (playMusicId: number): Promise<void> => {
|
||||
}
|
||||
|
||||
// 歌词矫正时间Correction time
|
||||
const correctionTime = ref(0)
|
||||
const correctionTime = ref(0.4)
|
||||
|
||||
// 增加矫正时间
|
||||
const addCorrectionTime = (time: number) => {
|
||||
|
||||
@@ -79,7 +79,7 @@ const getSongUrl = async (id: number) => {
|
||||
const { data } = await getMusicUrl(id)
|
||||
let url = ''
|
||||
try {
|
||||
if (data.data[0].freeTrialInfo) {
|
||||
if (data.data[0].freeTrialInfo || !data.data[0].url) {
|
||||
const res = await getParsingMusicUrl(id)
|
||||
url = res.data.data.url
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ watch(
|
||||
</div>
|
||||
<PlayBottom/>
|
||||
</n-scrollbar>
|
||||
<MusicList v-if="listDetail?.playlist" v-model:show="showMusic" :music-list="listDetail?.playlist" />
|
||||
<MusicList v-if="listDetail?.playlist" v-model:show="showMusic" :name="listDetail?.playlist.name" :song-list="listDetail?.playlist.tracks" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -123,7 +123,6 @@ const loadSearch = async (keywords: any) => {
|
||||
songs,
|
||||
albums
|
||||
}
|
||||
console.log('searchDetail',searchDetail.value)
|
||||
};
|
||||
|
||||
loadSearch(route.query.keyword);
|
||||
|
||||
@@ -145,7 +145,7 @@ const handlePlay = (item: any) => {
|
||||
</n-scrollbar>
|
||||
</div>
|
||||
</div>
|
||||
<MusicList v-if="list" v-model:show="isShowList" :music-list="list" />
|
||||
<MusicList v-if="list" v-model:show="isShowList" :name="list.name" :song-list="list.tracks" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user