refactor(Player): 提取获取当前曲目的逻辑到单独函数

将重复的获取当前曲目逻辑封装为 getCurrentTrack 函数,提高代码可维护性并避免重复代码
This commit is contained in:
Astrian Zheng 2025-05-26 13:24:10 +10:00
parent 0db105705b
commit 791fa0dbc7
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -181,6 +181,14 @@ watch(() => playQueueStore.playMode.shuffle, (isShuffle) => {
playQueueStore.currentIndex = playQueueStore.shuffleList[playQueueStore.currentIndex] playQueueStore.currentIndex = playQueueStore.shuffleList[playQueueStore.currentIndex]
} }
}) })
function getCurrentTrack() {
if (playQueueStore.playMode.shuffle) {
return playQueueStore.list[playQueueStore.shuffleList[playQueueStore.currentIndex]]
} else {
return playQueueStore.list[playQueueStore.currentIndex]
}
}
</script> </script>
<template> <template>
@ -217,12 +225,12 @@ watch(() => playQueueStore.playMode.shuffle, (isShuffle) => {
v-if="playQueueStore.list.length !== 0 && route.path !== '/playroom'" v-if="playQueueStore.list.length !== 0 && route.path !== '/playroom'"
> >
<RouterLink to="/playroom"> <RouterLink to="/playroom">
<img :src="playQueueStore.list[playQueueStore.currentIndex].album?.coverUrl ?? ''" class="rounded-full h-9 w-9" /> <img :src="getCurrentTrack().album?.coverUrl ?? ''" class="rounded-full h-9 w-9" />
</RouterLink> </RouterLink>
<RouterLink to="/playroom"> <RouterLink to="/playroom">
<div class="flex items-center w-32 h-9"> <div class="flex items-center w-32 h-9">
<span class="truncate">{{ playQueueStore.list[playQueueStore.currentIndex].song.name }}</span> <span class="truncate">{{ getCurrentTrack().song.name }}</span>
</div> </div>
</RouterLink> </RouterLink>