Zhangbw пре 3 месеци
родитељ
комит
77f01fa350
2 измењених фајлова са 49 додато и 5 уклоњено
  1. 21 2
      dist/dev/mp-weixin/components/StockListItem.js
  2. 28 3
      src/components/StockListItem.vue

+ 21 - 2
dist/dev/mp-weixin/components/StockListItem.js

@@ -20,19 +20,37 @@ const _sfc_main = {
     const moveX = common_vendor.ref(0);
     let currentX = 0;
     let autoResetTimer = null;
+    let checkTimer = null;
     const AUTO_RESET_DELAY = 2e3;
+    let lastSlideTime = 0;
     const startAutoResetTimer = () => {
+      lastSlideTime = Date.now();
       clearAutoResetTimer();
       autoResetTimer = setTimeout(() => {
-        moveX.value = 0;
-        currentX = 0;
+        if (moveX.value < 0) {
+          moveX.value = 0;
+          currentX = 0;
+        }
       }, AUTO_RESET_DELAY);
+      if (!checkTimer) {
+        checkTimer = setInterval(() => {
+          if (moveX.value < 0 && Date.now() - lastSlideTime > AUTO_RESET_DELAY) {
+            moveX.value = 0;
+            currentX = 0;
+            clearAutoResetTimer();
+          }
+        }, 500);
+      }
     };
     const clearAutoResetTimer = () => {
       if (autoResetTimer) {
         clearTimeout(autoResetTimer);
         autoResetTimer = null;
       }
+      if (checkTimer) {
+        clearInterval(checkTimer);
+        checkTimer = null;
+      }
     };
     const canvasId = common_vendor.ref(`chart-${props.stock.code}-${Math.random().toString(36).slice(2, 11)}`);
     const getMarketTag = (code) => {
@@ -153,6 +171,7 @@ const _sfc_main = {
     const handleMoveChange = (e) => {
       currentX = e.detail.x;
       if (props.showDelete && currentX <= -deleteWidth / 2) {
+        lastSlideTime = Date.now();
         startAutoResetTimer();
       }
     };

+ 28 - 3
src/components/StockListItem.vue

@@ -78,15 +78,35 @@ const deleteWidth = 60 // 删除按钮宽度(px)
 const moveX = ref(0)
 let currentX = 0
 let autoResetTimer = null // 自动还原计时器
+let checkTimer = null // 检查计时器
 const AUTO_RESET_DELAY = 2000 // 自动还原延迟时间(ms)
+let lastSlideTime = 0 // 最后滑动时间
 
 // 启动自动还原计时器
 const startAutoResetTimer = () => {
+  lastSlideTime = Date.now()
+  
+  // 清除之前的计时器
   clearAutoResetTimer()
+  
+  // 使用 setTimeout 作为主计时器
   autoResetTimer = setTimeout(() => {
-    moveX.value = 0
-    currentX = 0
+    if (moveX.value < 0) {
+      moveX.value = 0
+      currentX = 0
+    }
   }, AUTO_RESET_DELAY)
+  
+  // 使用 setInterval 作为备用检查,确保一定会返回
+  if (!checkTimer) {
+    checkTimer = setInterval(() => {
+      if (moveX.value < 0 && Date.now() - lastSlideTime > AUTO_RESET_DELAY) {
+        moveX.value = 0
+        currentX = 0
+        clearAutoResetTimer()
+      }
+    }, 500)
+  }
 }
 
 // 清除自动还原计时器
@@ -95,6 +115,10 @@ const clearAutoResetTimer = () => {
     clearTimeout(autoResetTimer)
     autoResetTimer = null
   }
+  if (checkTimer) {
+    clearInterval(checkTimer)
+    checkTimer = null
+  }
 }
 
 // 生成稳定的 canvas ID(只在组件创建时生成一次)
@@ -254,8 +278,9 @@ const generateMockTrendData = () => {
 // 滑动变化
 const handleMoveChange = (e) => {
   currentX = e.detail.x
-  // 如果滑动到了删除按钮位置,启动计时器
+  // 如果滑动到了删除按钮位置,更新最后滑动时间并启动计时器
   if (props.showDelete && currentX <= -deleteWidth / 2) {
+    lastSlideTime = Date.now()
     startAutoResetTimer()
   }
 }