@@ -324,6 +324,7 @@ const currentSong = ref<SongType | null>(null);
324324const viewModel = ref <WikiViewModel | null >(null );
325325const similarSongsList = ref <SongType []>([]);
326326const sheetLoading = ref <Record <number , boolean >>({});
327+ const currentRequestToken = ref (0 );
327328
328329const publishTime = computed (() => {
329330 const createTime = currentSong .value ?.createTime ;
@@ -423,9 +424,10 @@ const normalizeWikiData = (
423424};
424425
425426// 获取歌曲信息
426- const fetchData = async () => {
427- const id = Number (route .query .id );
427+ const fetchData = async (id ? : number ) => {
428+ id = id ?? Number (route .query .id );
428429 if (! id || id === currentSongId .value ) return ;
430+ const token = ++ currentRequestToken .value ;
429431 loading .value = true ;
430432 currentSongId .value = id ;
431433 viewModel .value = null ;
@@ -434,12 +436,14 @@ const fetchData = async () => {
434436 try {
435437 const detailRes = await songDetail (id );
436438 if (! detailRes .songs ?.[0 ]) throw new Error (" Song not found" );
439+ if (token !== currentRequestToken .value ) return ;
437440 currentSong .value = formatSongsList (detailRes .songs )[0 ];
438441 const [wikiRes, listenRes, sheetRes] = await Promise .allSettled ([
439442 songWikiSummary (id ),
440443 songFirstListenInfo (id ),
441444 songSheetList (id ),
442445 ]);
446+ if (token !== currentRequestToken .value ) return ;
443447 // 获取歌曲信息
444448 const wikiData = wikiRes .status === " fulfilled" ? wikiRes .value .data || wikiRes .value : {};
445449 const listenData =
@@ -453,6 +457,7 @@ const fetchData = async () => {
453457 if (viewModel .value .similarSongs .length > 0 ) {
454458 try {
455459 const sims = await songDetail (viewModel .value .similarSongs );
460+ if (token !== currentRequestToken .value ) return ;
456461 if (sims .songs ) similarSongsList .value = formatSongsList (sims .songs );
457462 } catch (e ) {
458463 console .warn (" Failed to load similar songs" , e );
@@ -462,7 +467,9 @@ const fetchData = async () => {
462467 console .error (" Fetch wiki failed" , error );
463468 window .$message .error (" 加载信息失败" );
464469 } finally {
465- loading .value = false ;
470+ if (token === currentRequestToken .value ) {
471+ loading .value = false ;
472+ }
466473 }
467474};
468475
@@ -491,11 +498,11 @@ const handlePlay = () => {
491498 if (currentSong .value ) player .addNextSong (currentSong .value , true );
492499};
493500
494- onActivated (() => {
495- const id = Number ( route . query . id );
496- if ( id && id !== currentSongId . value ) {
497- fetchData ();
498- }
501+ onActivated (() => fetchData ());
502+
503+ // 监听路由更新
504+ onBeforeRouteUpdate (( to ) => {
505+ fetchData ( Number ( to . query . id ));
499506});
500507 </script >
501508
0 commit comments