From 3608b02c4d89cd22563f8ebf7919724d1e9c5e2c Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Sun, 25 May 2025 15:52:52 +1000 Subject: [PATCH] =?UTF-8?q?refactor(Playroom):=20=E5=B0=86=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E5=8D=95=E7=8B=AC=E5=87=BD=E6=95=B0=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将进度条更新的逻辑提取到 `thumbUpdate` 函数中,以便在多个地方复用,提升代码的可维护性 --- src/pages/Playroom.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/Playroom.vue b/src/pages/Playroom.vue index 783c065..ae0ea48 100644 --- a/src/pages/Playroom.vue +++ b/src/pages/Playroom.vue @@ -26,7 +26,7 @@ onMounted(() => { playQueueStore.updatedCurrentTime = newTime } }) - + thumbUpdate() }) function timeFormatter(time: number) { @@ -40,12 +40,16 @@ function timeFormatter(time: number) { // 监听播放进度,更新进度条 watch(() => playQueueStore.currentTime, () => { + thumbUpdate() +}) + +function thumbUpdate() { const progress = playQueueStore.currentTime / playQueueStore.duration const containerWidth = progressBarContainer.value?.clientWidth || 0 const thumbWidth = progressBarThumb.value?.clientWidth || 0 const newPosition = (containerWidth - thumbWidth) * progress gsap.to(progressBarThumb.value, { x: newPosition, duration: 0.1 }) -}) +} function formatDetector() { const format = playQueueStore.list[playQueueStore.currentIndex].song.sourceUrl?.split('.').pop()