Skip to content

Commit b14b29f

Browse files
committed
🐞 fix: 修复歌词不必要的重载
1 parent d28a234 commit b14b29f

5 files changed

Lines changed: 44 additions & 21 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@pixi/filter-bulge-pinch": "^5.1.1",
4949
"@pixi/filter-color-matrix": "^7.4.3",
5050
"@pixi/sprite": "^7.4.3",
51-
"@tanstack/vue-virtual": "^3.13.13",
5251
"@vueuse/core": "^13.9.0",
5352
"@vueuse/integrations": "^14.1.0",
5453
"axios": "^1.13.2",

pnpm-lock.yaml

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Player/MainAMLyric.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:key="amLyricsData?.[0]?.words?.length"
55
:class="['lyric-am', { pure: statusStore.pureLyricMode }]"
66
:style="{
7-
'--amll-lp-color': 'rgb(239 239 239)',
7+
'--amll-lp-color': 'rgb(var(--main-cover-color, 239 239 239))',
88
}"
99
>
1010
<div v-if="statusStore.lyricLoading" class="lyric-loading">歌词正在加载中...</div>

src/components/Setting/PlaySetting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
/>
112112
</n-card>
113113
</div>
114-
<div v-if="isElectron&& statusStore.isDeveloperMode" class="set-list">
114+
<div v-if="isElectron && statusStore.isDeveloperMode" class="set-list">
115115
<n-h3 prefix="bar">
116116
音乐解锁
117117
<n-tag type="warning" size="small" round>Beta</n-tag>

src/core/player/LyricManager.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,42 @@ class LyricManager {
350350
};
351351
}
352352

353+
/**
354+
* 比较歌词数据是否相同
355+
* @param oldData 旧歌词数据
356+
* @param newData 新歌词数据
357+
* @returns 是否相同
358+
*/
359+
private isLyricDataEqual(oldData: SongLyric, newData: SongLyric): boolean {
360+
// 比较数组长度
361+
if (
362+
oldData.lrcData?.length !== newData.lrcData?.length ||
363+
oldData.yrcData?.length !== newData.yrcData?.length
364+
) {
365+
return false;
366+
}
367+
// 比较 lrcData 内容(比较每行的 startTime 和文本内容)
368+
const compareLines = (oldLines: LyricLine[], newLines: LyricLine[]): boolean => {
369+
if (oldLines.length !== newLines.length) return false;
370+
for (let i = 0; i < oldLines.length; i++) {
371+
const oldLine = oldLines[i];
372+
const newLine = newLines[i];
373+
const oldText = oldLine.words?.map((w) => w.word).join("") || "";
374+
const newText = newLine.words?.map((w) => w.word).join("") || "";
375+
if (oldLine.startTime !== newLine.startTime || oldText !== newText) {
376+
return false;
377+
}
378+
// ttml 特有属性
379+
if (newLine.isBG !== oldLine.isBG) return false;
380+
}
381+
return true;
382+
};
383+
return (
384+
compareLines(oldData.lrcData || [], newData.lrcData || []) &&
385+
compareLines(oldData.yrcData || [], newData.yrcData || [])
386+
);
387+
}
388+
353389
/**
354390
* 设置最终歌词
355391
* @param lyricData 歌词数据
@@ -375,6 +411,12 @@ class LyricManager {
375411
],
376412
}));
377413
}
414+
// 比较新旧歌词数据,如果相同则跳过设置,避免重复重载
415+
if (this.isLyricDataEqual(musicStore.songLyric, lyricData)) {
416+
// 仅更新加载状态,不更新歌词数据
417+
statusStore.lyricLoading = false;
418+
return;
419+
}
378420
// 设置歌词
379421
musicStore.setSongLyric(lyricData, true);
380422
// 结束加载状态

0 commit comments

Comments
 (0)