From b4dc67fda148d0e027187c9d1baae427c6875f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=90=A6?= Date: Sat, 1 Aug 2026 18:13:02 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=92=AD=E6=94=BE=E5=99=A8=E6=AD=8C?= =?UTF-8?q?=E8=AF=8D=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite-tailwindcss/src/composables/useAudio.js | 25 +++ vite-tailwindcss/src/views/index/index.vue | 186 ++++++++++++++----- 2 files changed, 169 insertions(+), 42 deletions(-) diff --git a/vite-tailwindcss/src/composables/useAudio.js b/vite-tailwindcss/src/composables/useAudio.js index d0b95a2..a957a87 100644 --- a/vite-tailwindcss/src/composables/useAudio.js +++ b/vite-tailwindcss/src/composables/useAudio.js @@ -84,6 +84,28 @@ export function useAudio() { } } + const currentIndex = computed(() => tracks.value.findIndex((t) => t.url === activeUrl.value)) + + const playAt = (index) => { + const list = tracks.value + if (!list.length) return + const i = ((index % list.length) + list.length) % list.length + const url = list[i]?.url + if (!url) return + if (isPlaying.value) playUrl(url) + else setActive(url) + } + + const prev = () => { + const idx = currentIndex.value + playAt(idx < 0 ? 0 : idx - 1) + } + + const next = () => { + const idx = currentIndex.value + playAt(idx < 0 ? 0 : idx + 1) + } + const play = () => playUrl(activeUrl.value) const attemptAutoplay = async () => { @@ -154,8 +176,11 @@ export function useAudio() { currentTime, duration, volume, + currentIndex, setTracks, setActive, + prev, + next, play, pause, toggle, diff --git a/vite-tailwindcss/src/views/index/index.vue b/vite-tailwindcss/src/views/index/index.vue index a93cbea..630b5ac 100644 --- a/vite-tailwindcss/src/views/index/index.vue +++ b/vite-tailwindcss/src/views/index/index.vue @@ -46,25 +46,8 @@
- +
-
-
- -
-
-
选择曲目
-
-
- - {{ t.name }} - -
-
-
-
@@ -166,17 +149,52 @@

暂无歌词

- +