第一次提交

This commit is contained in:
2026-05-07 22:27:55 +08:00
commit 463e8e95b6
95 changed files with 13167 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import { ref, computed, watch } from 'vue';
import { invoke } from '@tauri-apps/api/core';
import { parseLrc, getCurrentLyricIndex, LyricLine } from '../utils/lyric';
import { usePlayerStore } from '../stores/player';
export function useLyric() {
const player = usePlayerStore();
const lyrics = ref<LyricLine[]>([]);
const currentLyricIdx = ref(-1);
const currentLyricText = computed(() => {
if (lyrics.value.length === 0) return '';
const idx = currentLyricIdx.value;
return idx >= 0 && idx < lyrics.value.length ? lyrics.value[idx].text : '';
});
watch(() => player.currentSong, async (song) => {
if (!song) {
lyrics.value = [];
currentLyricIdx.value = -1;
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) : [];
currentLyricIdx.value = -1;
} catch {
lyrics.value = [];
}
}, { immediate: true });
watch(() => player.currentTime, (t) => {
if (lyrics.value.length === 0) return;
const idx = getCurrentLyricIndex(lyrics.value, t);
if (idx !== currentLyricIdx.value) {
currentLyricIdx.value = idx;
}
});
return {
lyrics,
currentLyricIdx,
currentLyricText,
};
}