修复歌词显示错误

This commit is contained in:
灌糖包子 2023-01-26 06:16:39 +08:00
parent b0e8e8aab3
commit 289d7e0b8b
Signed by: sookie
GPG Key ID: 691E688C160D3188
2 changed files with 9 additions and 17 deletions

View File

@ -18,10 +18,10 @@
<script lang="ts" setup>
import { computed, watch, ref } from 'vue'
import { parseLrc } from '../utils'
import { MusicPlayerItem, StatType } from '@/model/api/music'
import { StatType } from '@/model/api/music'
const props = defineProps<{
currentMusic: MusicPlayerItem,
lrcSource: string,
playStat: StatType
}>()
@ -37,22 +37,14 @@ const transformStyle = computed(() => {
}
})
const applyLrc = (lrc: string) => {
if (/^https?:\/\//.test(lrc)) {
fetch(lrc)
.then(response => response.text())
.then((lrc) => displayLrc.value = lrc)
} else {
displayLrc.value = lrc
}
}
watch(props.currentMusic, (music: MusicPlayerItem) => {
watch(() => props.lrcSource, (lrcSource: string) => {
currentLineIndex.value = 0
if (music.lrc) {
applyLrc(music.lrc)
if (/^https?:\/\//.test(lrcSource)) {
fetch(lrcSource)
.then(response => response.text())
.then(lrc => displayLrc.value = lrc)
} else {
displayLrc.value = ''
displayLrc.value = lrcSource
}
}, { immediate: true })

View File

@ -26,7 +26,7 @@
<span class="aplayer-author">{{ currentMusic.artist || currentMusic.author || 'Unknown' }}</span>
</div>
<slot name="display" :current-music="currentMusic" :play-stat="playStat">
<lyrics :current-music="currentMusic" :play-stat="playStat" v-if="showLrc && currentMusic.lrc" />
<lyrics :lrc-source="currentMusic.lrc" :play-stat="playStat" v-if="showLrc && currentMusic.lrc" />
</slot>
<controls
:shuffle="shouldShuffle"