Skip to content

Commit e48fe46

Browse files
committed
fix:修复歌曲作者信息跳转更新失败和作者头像丢失问题
1 parent ff8516e commit e48fe46

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/components/Modal/JumpArtist.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<script setup lang="ts">
2828
import type { SongType, MetaData } from "@/types/main";
2929
import { useSettingStore } from "@/stores";
30-
import { searchArtist } from "@/api/artist";
30+
import { searchArtist, artistDetail } from "@/api/artist";
3131
import { uniq } from "lodash-es";
3232
3333
const props = defineProps<{
@@ -86,7 +86,27 @@ const getArtistData = async () => {
8686
});
8787
}
8888
} else if (Array.isArray(props.artist)) {
89-
artistData.value = props.artist;
89+
// 检查是否有 cover 字段,如果没有则获取歌手详情
90+
const hasCover = props.artist.some((ar) => ar.cover);
91+
if (hasCover) {
92+
artistData.value = props.artist;
93+
} else {
94+
// 获取每个歌手的详情以获取头像
95+
const artistPromises = props.artist.map(async (ar) => {
96+
try {
97+
const result = await artistDetail(ar.id);
98+
const artist = result.data?.artist;
99+
return {
100+
id: ar.id,
101+
name: ar.name,
102+
cover: artist?.cover || artist?.img1v1Url || artist?.picUrl,
103+
};
104+
} catch {
105+
return { id: ar.id, name: ar.name, cover: undefined };
106+
}
107+
});
108+
artistData.value = await Promise.all(artistPromises);
109+
}
90110
}
91111
};
92112

src/views/Artist/layout.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ const listScroll = (e: Event) => {
251251
252252
onBeforeRouteUpdate((to) => {
253253
listScrolling.value = false;
254-
if (to.matched[0].name !== "artist") return;
254+
// 检查是否仍在 artist 路由下
255+
const isArtistRoute = to.matched.some((m) => m.name === "artist");
256+
if (!isArtistRoute) return;
255257
artistType.value = to.name as string;
256258
const id = Number(to.query.id as string);
257259
if (id && id !== artistId.value) getArtistDetail(id);

0 commit comments

Comments
 (0)