From f36f777e655b22f28017c4f3bca3945cf9812aa1 Mon Sep 17 00:00:00 2001 From: alger Date: Sun, 15 Mar 2026 14:55:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(lyric):=20=E6=89=A9=E5=B1=95=20lyricSettin?= =?UTF-8?q?g=20=E6=94=AF=E6=8C=81=20showTranslation=20=E5=92=8C=20displayM?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/views/lyric/index.vue | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/renderer/views/lyric/index.vue b/src/renderer/views/lyric/index.vue index 0e84f32..529aaa5 100644 --- a/src/renderer/views/lyric/index.vue +++ b/src/renderer/views/lyric/index.vue @@ -188,7 +188,11 @@ const loadLyricSettings = () => { isTop: parsed.isTop ?? false, theme: parsed.theme === 'light' || parsed.theme === 'dark' ? parsed.theme : 'dark', isLock: parsed.isLock ?? false, - highlightColor: validatedHighlightColor + highlightColor: validatedHighlightColor, + showTranslation: parsed.showTranslation ?? true, + displayMode: (['scroll', 'single', 'double'].includes(parsed.displayMode) + ? parsed.displayMode + : 'scroll') as 'scroll' | 'single' | 'double' }; } } catch (error) { @@ -200,7 +204,9 @@ const loadLyricSettings = () => { isTop: false, theme: 'dark' as 'light' | 'dark', isLock: false, - highlightColor: undefined as string | undefined + highlightColor: undefined as string | undefined, + showTranslation: true, + displayMode: 'scroll' as 'scroll' | 'single' | 'double' }; }; @@ -424,13 +430,19 @@ onMounted(() => { // 实际播放时间 const actualTime = ref(0); -// 计算当前行的进度 +// 计算当前行的进度(从本地 lrcTimeArray 取时间,避免依赖 IPC 传入的 startCurrentTime/nextTime) +// 注意:lrcTimeArray 单位为毫秒(来自 yrcParser),actualTime 单位为秒,需要 * 1000 对齐 const currentProgress = computed(() => { - const { startCurrentTime, nextTime } = dynamicData.value; - if (!startCurrentTime || !nextTime) return 0; + const times = staticData.value.lrcTimeArray; + const idx = currentIndex.value; + const startTimeMs = times[idx]; + const endTimeMs = times[idx + 1]; + // 使用严格判断,避免 startTimeMs=0 时被误判为无效 + if (startTimeMs === undefined || endTimeMs === undefined || endTimeMs <= startTimeMs) return 0; - const duration = nextTime - startCurrentTime; - const elapsed = actualTime.value - startCurrentTime; + const currentTimeMs = actualTime.value * 1000; // seconds → ms,与 lrcTimeArray 单位对齐 + const elapsed = currentTimeMs - startTimeMs; + const duration = endTimeMs - startTimeMs; return Math.min(Math.max(elapsed / duration, 0), 1); });