🎈 perf: 优化歌曲列表以及图片加载

This commit is contained in:
alger
2024-06-05 15:35:31 +08:00
parent 9fcf455c08
commit 2f851f3172
4 changed files with 42 additions and 21 deletions
+26 -9
View File
@@ -9,16 +9,20 @@
<i class="iconfont icon-icon_error music-close" @click="close"></i> <i class="iconfont icon-icon_error music-close" @click="close"></i>
<div class="music-title text-el">{{ name }}</div> <div class="music-title text-el">{{ name }}</div>
<!-- 歌单歌曲列表 --> <!-- 歌单歌曲列表 -->
<div class="music-list"> <div :show="loading" class="music-list">
<n-scrollbar> <n-scrollbar>
<div <n-spin :show="loading">
v-for="(item, index) in songList" <div class="music-list-content">
:key="item.id" <div
:class="setAnimationClass('animate__bounceInUp')" v-for="(item, index) in songList"
:style="setAnimationDelay(index, 50)" :key="item.id"
> :class="setAnimationClass('animate__bounceInUp')"
<song-item :item="formatDetail(item)" @play="handlePlay" /> :style="setAnimationDelay(index, 50)"
</div> >
<song-item :item="formatDetail(item)" @play="handlePlay" />
</div>
</div>
</n-spin>
<play-bottom /> <play-bottom />
</n-scrollbar> </n-scrollbar>
</div> </div>
@@ -34,6 +38,8 @@ import { isMobile, setAnimationClass, setAnimationDelay } from '@/utils';
import PlayBottom from './common/PlayBottom.vue'; import PlayBottom from './common/PlayBottom.vue';
const loading = ref(true);
const store = useStore(); const store = useStore();
const props = defineProps<{ const props = defineProps<{
@@ -43,6 +49,14 @@ const props = defineProps<{
}>(); }>();
const emit = defineEmits(['update:show']); const emit = defineEmits(['update:show']);
watch(
() => props.songList,
(val) => {
loading.value = !(val && val.length);
},
{ immediate: true },
);
const formatDetail = computed(() => (detail: any) => { const formatDetail = computed(() => (detail: any) => {
const song = { const song = {
artists: detail.ar, artists: detail.ar,
@@ -81,6 +95,9 @@ const close = () => {
&-list { &-list {
height: calc(100% - 60px); height: calc(100% - 60px);
&-content {
min-height: 400px;
}
} }
} }
+5 -2
View File
@@ -60,8 +60,11 @@ export const getMusicProxyUrl = (url: string) => {
export const getImgUrl = computed(() => (url: string | undefined, size: string = '') => { export const getImgUrl = computed(() => (url: string | undefined, size: string = '') => {
const bdUrl = 'https://image.baidu.com/search/down?url='; const bdUrl = 'https://image.baidu.com/search/down?url=';
const imgUrl = encodeURIComponent(`${url}?param=${size}`); const imgUrl = `${url}?param=${size}`;
return `${bdUrl}${imgUrl}`; if (!getIsMc()) {
return imgUrl;
}
return `${bdUrl}${encodeURIComponent(imgUrl)}`;
}); });
export const isMobile = computed(() => { export const isMobile = computed(() => {
+3 -4
View File
@@ -20,8 +20,8 @@ const selectRecommendItem = async (item: IRecommendItem) => {
recommendItem.value = null; recommendItem.value = null;
listDetail.value = null; listDetail.value = null;
showMusic.value = true; showMusic.value = true;
const { data } = await getListDetail(item.id);
recommendItem.value = item; recommendItem.value = item;
const { data } = await getListDetail(item.id);
listDetail.value = data; listDetail.value = data;
}; };
@@ -90,10 +90,9 @@ watch(
</div> </div>
</n-scrollbar> </n-scrollbar>
<music-list <music-list
v-if="listDetail?.playlist"
v-model:show="showMusic" v-model:show="showMusic"
:name="listDetail?.playlist.name" :name="recommendItem?.name || ''"
:song-list="listDetail?.playlist.tracks" :song-list="listDetail?.playlist.tracks || []"
/> />
</div> </div>
</template> </template>
+8 -6
View File
@@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { onBeforeRouteUpdate, useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { getListDetail } from '@/api/list'; import { getListDetail } from '@/api/list';
@@ -36,8 +36,9 @@ const loadPage = async () => {
const { data: playlistData } = await getUserPlaylist(user.value.userId); const { data: playlistData } = await getUserPlaylist(user.value.userId);
playList.value = playlistData.playlist; playList.value = playlistData.playlist;
const { data: recordData } = await getUserRecord(user.value.userId); getUserRecord(user.value.userId).then(({ data: recordData }) => {
recordList.value = recordData.allData; recordList.value = recordData.allData;
});
}; };
onActivated(() => { onActivated(() => {
@@ -52,8 +53,9 @@ const isShowList = ref(false);
const list = ref<Playlist>(); const list = ref<Playlist>();
// 展示歌单 // 展示歌单
const showPlaylist = async (id: number) => { const showPlaylist = async (id: number) => {
const { data } = await getListDetail(id);
isShowList.value = true; isShowList.value = true;
list.value = {};
const { data } = await getListDetail(id);
list.value = data.playlist; list.value = data.playlist;
}; };
@@ -77,7 +79,7 @@ const handlePlay = () => {
</script> </script>
<template> <template>
<div class="user-page" @click.stop="isShowList = false"> <div class="user-page">
<div <div
v-if="userDetail" v-if="userDetail"
class="left" class="left"
@@ -138,7 +140,7 @@ const handlePlay = () => {
</n-scrollbar> </n-scrollbar>
</div> </div>
</div> </div>
<music-list v-if="list" v-model:show="isShowList" :name="list.name" :song-list="list.tracks" /> <music-list v-model:show="isShowList" :name="list?.name || ''" :song-list="list?.tracks || []" />
</div> </div>
</template> </template>