refactor(Player): 提取获取当前曲目的逻辑到单独函数
将重复的获取当前曲目逻辑封装为 getCurrentTrack 函数,提高代码可维护性并避免重复代码
This commit is contained in:
parent
0db105705b
commit
791fa0dbc7
|
@ -181,6 +181,14 @@ watch(() => playQueueStore.playMode.shuffle, (isShuffle) => {
|
|||
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>
|
||||
|
||||
<template>
|
||||
|
@ -217,12 +225,12 @@ watch(() => playQueueStore.playMode.shuffle, (isShuffle) => {
|
|||
v-if="playQueueStore.list.length !== 0 && route.path !== '/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 to="/playroom">
|
||||
<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>
|
||||
</RouterLink>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user