From 9169b7e838f34e7a9d3de320b21b48d7a1d5174a Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Mon, 3 Nov 2025 09:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=B7=83=E5=BC=8F=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=EF=BC=8C=E6=9A=82=E4=B8=8D=E5=B9=B3=E6=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 93f9c04..a973434 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -215,6 +215,7 @@ const translateX = ref(-375); // 当前滑动偏移量,初始值设为 -375( const baseTranslateX = ref(-375); // 基础偏移量 const isAnimating = ref(false); // 是否正在执行动画 const isDragging = ref(false); // 是否正在拖动 +const isInitialized = ref(false); // 是否已完成初始化 // 初始化屏幕宽度 const initScreenWidth = () => { @@ -222,10 +223,11 @@ const initScreenWidth = () => { success: (res) => { const width = res.windowWidth || res.screenWidth || 375; screenWidth.value = width; - // 只有在初始值时才更新,避免覆盖用户操作 - if (translateX.value === -375) { + // 只有在未初始化时才更新,避免覆盖用户操作 + if (!isInitialized.value) { translateX.value = -width; baseTranslateX.value = -width; + isInitialized.value = true; } } }); @@ -249,10 +251,10 @@ const handleTouchMove = (e) => { const deltaX = touch.clientX - touchStartX.value; const deltaY = Math.abs(touch.clientY - touchStartY.value); - // 如果是水平滑动(水平距离大于垂直距离),阻止页面滚动 - if (Math.abs(deltaX) > deltaY && Math.abs(deltaX) > 10) { - e.preventDefault(); - } + // // 如果是水平滑动(水平距离大于垂直距离),阻止页面滚动 + // if (Math.abs(deltaX) > deltaY && Math.abs(deltaX) > 10) { + // e.preventDefault(); + // } // 实时更新偏移量 translateX.value = baseTranslateX.value + deltaX; @@ -280,10 +282,10 @@ const handleTouchEnd = (e) => { if (isHorizontalSwipe) { // 滑动距离超过阈值,自动滑动到下一个页面 if (deltaX > 0) { - // 向右滑动,滑动到前一天的位置 - // slideToPreviousDay(); + // 向左滑动,滑动到前一天的位置 + slideToPreviousDay(); } else { - // 向左滑动,滑动到后一天的位置 + // 向右滑动,滑动到后一天的位置 slideToNextDay(); } } else { @@ -306,12 +308,12 @@ const resetToCenter = () => { const slideToPreviousDay = () => { isAnimating.value = true; // 从当前位置继续滑动到前一天的完整位置(-screenWidth * 2) - const targetX = -screenWidth.value*2; - translateX.value = targetX; + // const targetX = -screenWidth.value*2; + // translateX.value = targetX; setTimeout(() => { // 滑动动画完成后,先暂时禁用 transition - isAnimating.value = false; + // isAnimating.value = false; // 在下一帧更新日期和重置位置(确保没有 transition 动画) setTimeout(() => { @@ -327,14 +329,15 @@ const slideToPreviousDay = () => { console.log(`日期切换:上一天,新日期:${selectedDate.value}`); }, 16); // 一帧的时间,确保 transition 已禁用 }, 1000); + isAnimating.value = false; }; // 滑动到后一天的位置(动画完成后更新日期) const slideToNextDay = () => { isAnimating.value = true; // 从当前位置继续滑动到后一天的完整位置(0) - const targetX = 0; - translateX.value = targetX; + // const targetX = 0; + // translateX.value = targetX; setTimeout(() => { // 滑动动画完成后,先暂时禁用 transition @@ -353,7 +356,7 @@ const slideToNextDay = () => { console.log(`日期切换:下一天,新日期:${selectedDate.value}`); }, 16); // 一帧的时间,确保 transition 已禁用 - }, 1000); + }, 300); }; // 监听日期变化,重置位置