|
|
@@ -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()
|
|
|
}
|
|
|
}
|