重构播放列表为右侧弹出式

播放列表可以定位正在播放的歌曲位置
添加歌词翻译
新增快捷键 播放/暂停
重构主题设置,支持多种主题

修复评论playerbar查看点击后一直默认评论打开抽屉页面问题
This commit is contained in:
2026-05-22 00:54:09 +08:00
parent cf21c96eaf
commit 970fb15f5a
9 changed files with 415 additions and 115 deletions

View File

@ -1,6 +1,6 @@
import { ref, watch } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { parseLrc, getCurrentLyricIndex, LyricLine } from '../utils/lyric';
import { parseLrc, mergeTranslation, getCurrentLyricIndex, LyricLine } from '../utils/lyric';
import { usePlayerStore } from '../stores/player';
export function useLyric() {
@ -8,21 +8,33 @@ export function useLyric() {
const lyrics = ref<LyricLine[]>([]);
const currentLyricIdx = ref(-1);
const showTranslation = ref(true);
const hasTranslation = ref(false);
watch(() => player.currentSong, async (song) => {
if (!song) {
lyrics.value = [];
currentLyricIdx.value = -1;
hasTranslation.value = false;
return;
}
try {
const jsonStr: string = await invoke('get_lyric', { id: song.id });
const data = JSON.parse(jsonStr);
const lrc = data?.lrc?.lyric || '';
lyrics.value = lrc ? parseLrc(lrc) : [];
const tLrc = data?.tlyric?.lyric || '';
let parsed = lrc ? parseLrc(lrc) : [];
if (tLrc && parsed.length > 0) {
parsed = mergeTranslation(parsed, tLrc);
hasTranslation.value = parsed.some(l => l.translation);
} else {
hasTranslation.value = false;
}
lyrics.value = parsed;
currentLyricIdx.value = -1;
} catch {
lyrics.value = [];
hasTranslation.value = false;
}
}, { immediate: true });
@ -34,8 +46,15 @@ export function useLyric() {
}
});
function toggleTranslation() {
showTranslation.value = !showTranslation.value;
}
return {
lyrics,
currentLyricIdx,
hasTranslation,
showTranslation,
toggleTranslation,
};
}
}