From 28b521a1929daa8e8741f171e0e82f63c8f672a9 Mon Sep 17 00:00:00 2001 From: imsyy Date: Fri, 31 Oct 2025 00:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=A1=8C=E9=9D=A2=E6=AD=8C=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 1 - src/assets/icons/Collapse.svg | 1 + src/assets/icons/Expand.svg | 1 + src/components/Player/MainPlayer.vue | 2 +- src/views/DesktopLyrics/index.d.ts | 2 + src/views/DesktopLyrics/index.vue | 57 ++++++++++++++++++++++++++-- 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/assets/icons/Collapse.svg create mode 100644 src/assets/icons/Expand.svg diff --git a/components.d.ts b/components.d.ts index 79a4bd1..11a6d09 100644 --- a/components.d.ts +++ b/components.d.ts @@ -106,7 +106,6 @@ declare module 'vue' { NSlider: typeof import('naive-ui')['NSlider'] NSpin: typeof import('naive-ui')['NSpin'] NSwitch: typeof import('naive-ui')['NSwitch'] - NTab: typeof import('naive-ui')['NTab'] NTabPane: typeof import('naive-ui')['NTabPane'] NTabs: typeof import('naive-ui')['NTabs'] NTag: typeof import('naive-ui')['NTag'] diff --git a/src/assets/icons/Collapse.svg b/src/assets/icons/Collapse.svg new file mode 100644 index 0000000..8b4878a --- /dev/null +++ b/src/assets/icons/Collapse.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/icons/Expand.svg b/src/assets/icons/Expand.svg new file mode 100644 index 0000000..5ca4e8b --- /dev/null +++ b/src/assets/icons/Expand.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/Player/MainPlayer.vue b/src/components/Player/MainPlayer.vue index 06220f9..15ab2c8 100644 --- a/src/components/Player/MainPlayer.vue +++ b/src/components/Player/MainPlayer.vue @@ -42,7 +42,7 @@ - + diff --git a/src/views/DesktopLyrics/index.d.ts b/src/views/DesktopLyrics/index.d.ts index e6c1cff..36c07a3 100644 --- a/src/views/DesktopLyrics/index.d.ts +++ b/src/views/DesktopLyrics/index.d.ts @@ -11,6 +11,8 @@ export interface LyricData { /** 歌词数据 */ lrcData: LyricType[]; yrcData: LyricType[]; + /** 歌词播放索引 */ + lyricIndex: number; } /** 桌面歌词配置 */ diff --git a/src/views/DesktopLyrics/index.vue b/src/views/DesktopLyrics/index.vue index 8d92d7d..7cbe8ad 100644 --- a/src/views/DesktopLyrics/index.vue +++ b/src/views/DesktopLyrics/index.vue @@ -1,8 +1,14 @@ @@ -54,6 +72,7 @@ const lyricData = reactive({ progress: 0, lrcData: [], yrcData: [], + lyricIndex: -1, }); // 桌面歌词配置 @@ -73,6 +92,36 @@ const lyricConfig = reactive({ // 桌面歌词元素 const desktopLyricsRef = useTemplateRef("desktopLyricsRef"); +// 需要显示的歌词行 +const displayLyricLines = computed(() => { + // 优先使用逐字歌词,无则使用普通歌词 + const lyrics = lyricData.yrcData.length ? lyricData.yrcData : lyricData.lrcData; + if (!lyrics.length) return ["纯音乐,请欣赏"]; + // 当前播放歌词索引 + let idx = lyricData.lyricIndex; + if (idx < 0) idx = 0; // 开头之前按首句处理 + // 当前与下一句 + const current = lyrics[idx]; + const next = lyrics[idx + 1]; + if (!current) return []; + // 若当前句有翻译,无论单/双行设置都显示两行:原文 + 翻译 + if (current.tran && current.tran.trim().length > 0) { + return [current.content, current.tran]; + } + // 单行:仅返回当前句原文 + if (!lyricConfig.isDoubleLine) { + return [current.content]; + } + // 双行:两行内容交替 + const isEven = idx % 2 === 0; + if (isEven) { + // 偶数句:第一行当前句,第二行下一句 + return [current.content, next?.content ?? ""]; + } + // 奇数句:第一行下一句,第二行当前句 + return [next?.content ?? "", current.content]; +}); + // 桌面歌词拖动 const lyricDragMove = (position: Position) => { console.log(position); @@ -112,6 +161,8 @@ onMounted(() => { font-size: 1em; text-align: left; flex: 1 1 auto; + line-height: 36px; + padding: 0 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis;