Skip to content

Commit 8ef6b98

Browse files
authored
Merge pull request #632 from flystar233/dev
fix:修复歌手信息跳转更新失败和歌手头像丢失问题
2 parents 76f2555 + 3193861 commit 8ef6b98

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 artistPromises = props.artist.map(async (ar) => {
91+
// 如果已有封面,则直接返回
92+
if (ar.cover) {
93+
return ar;
94+
}
95+
// 否则,获取歌手详情
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 (error) {
105+
console.error(`获取歌手 ${ar.name} (${ar.id}) 的详情失败:`, error);
106+
return { id: ar.id, name: ar.name, cover: undefined };
107+
}
108+
});
109+
artistData.value = await Promise.all(artistPromises);
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)