From ba95dc11fe69c87c74736e9bf56dc031cd156084 Mon Sep 17 00:00:00 2001 From: alger Date: Sun, 19 Jan 2025 13:35:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E4=BC=98=E5=8C=96=E6=AD=8C?= =?UTF-8?q?=E8=AF=8D=E4=B8=8B=E4=B8=80=E9=A6=96=E7=9A=84=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/layout/components/MusicFull.vue | 23 ++++++++++++++++++-- src/renderer/utils/linearColor.ts | 1 - 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/renderer/layout/components/MusicFull.vue b/src/renderer/layout/components/MusicFull.vue index 2f5b5f0..38a51c1 100644 --- a/src/renderer/layout/components/MusicFull.vue +++ b/src/renderer/layout/components/MusicFull.vue @@ -227,9 +227,21 @@ const isVisible = computed({ }); // 歌词滚动方法 -const lrcScroll = (behavior: ScrollBehavior = 'smooth') => { +const lrcScroll = (behavior: ScrollBehavior = 'smooth', forceTop: boolean = false) => { + if (!isVisible.value || !lrcSider.value) return; + + if (forceTop) { + lrcSider.value.scrollTo({ + top: 0, + behavior + }); + return; + } + + if (isMouse.value) return; + const nowEl = document.querySelector(`#music-lrc-text-${nowIndex.value}`) as HTMLElement; - if (isVisible.value && !isMouse.value && nowEl && lrcSider.value) { + if (nowEl) { const containerHeight = lrcSider.value.$el.clientHeight; const elementTop = nowEl.offsetTop; const scrollTop = elementTop - containerHeight / 2 + nowEl.clientHeight / 2; @@ -479,6 +491,13 @@ onMounted(() => { } }); +// 添加对 playMusic 的监听 +watch(playMusic, () => { + nextTick(() => { + lrcScroll('instant', true); + }); +}); + defineExpose({ lrcScroll, config diff --git a/src/renderer/utils/linearColor.ts b/src/renderer/utils/linearColor.ts index e46ad4d..08334ec 100644 --- a/src/renderer/utils/linearColor.ts +++ b/src/renderer/utils/linearColor.ts @@ -152,7 +152,6 @@ export const getTextColors = (gradient: string = ''): ITextColors => { if (!gradient) return defaultColors; const colors = parseGradient(gradient); - console.log('colors', colors); if (!colors.length) return defaultColors; const mainColor = colors.length === 1 ? colors[0] : colors[1] || colors[0];