diff --git a/music-qianduan/src/components/MusicPlayer.vue b/music-qianduan/src/components/MusicPlayer.vue index f8225f0..0656e4e 100644 --- a/music-qianduan/src/components/MusicPlayer.vue +++ b/music-qianduan/src/components/MusicPlayer.vue @@ -380,11 +380,13 @@ const loopModeText = computed(() => { // 解析歌词 const parsedLyric = computed(() => { - if (!currentMusic.value || !currentMusic.value.lyric) return []; + if (!currentMusic.value || typeof currentMusic.value.lyric !== 'string') { + return []; + } const lyric = currentMusic.value.lyric; const lines = lyric.split('\n'); const result = []; - const timeRegExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/g; + const timeRegExp = /\[(\d{2}):(\d{2})\.(\d+)\]/g; for (const line of lines) { const text = line.replace(timeRegExp, '').trim(); @@ -394,8 +396,8 @@ const parsedLyric = computed(() => { while ((match = timeRegExp.exec(line)) !== null) { const min = parseInt(match, 10); const sec = parseInt(match, 10); - const ms = parseInt((match || '0').padEnd(3, '0'), 10); - const time = min * 60 + sec + ms / 1000; + const msStr = match; + const time = min * 60 + sec + parseFloat('0.' + msStr); result.push({ time, text }); } } @@ -574,7 +576,7 @@ watch(() => currentMusic.value?.id, (newId) => { lyricLines.value = {} if (isExpanded.value) expandedActiveTab.value = 'lyric' } -}, { immediate: true }) +})