isPressing 修改为 ref<boolean>

This commit is contained in:
icssoa
2025-10-17 23:22:07 +08:00
parent 436b06fee1
commit e1b746f38d

View File

@@ -1,5 +1,5 @@
import { vibrate } from "@/uni_modules/cool-vibrate"; import { vibrate } from "@/uni_modules/cool-vibrate";
import { onUnmounted } from "vue"; import { onUnmounted, ref, type Ref } from "vue";
// 长按触发延迟时间,单位毫秒 // 长按触发延迟时间,单位毫秒
const DELAY = 500; const DELAY = 500;
@@ -17,7 +17,7 @@ type UseLongPress = {
// 清除定时器 // 清除定时器
clear: () => void; clear: () => void;
// 是否正在长按中 // 是否正在长按中
isPressing: boolean; isPressing: Ref<boolean>;
}; };
/** /**
@@ -25,12 +25,12 @@ type UseLongPress = {
* 支持长按持续触发,可用于数字输入框等需要连续操作的场景 * 支持长按持续触发,可用于数字输入框等需要连续操作的场景
*/ */
export const useLongPress = (): UseLongPress => { export const useLongPress = (): UseLongPress => {
// 是否正在长按中
const isPressing = ref(false);
// 长按延迟定时器 // 长按延迟定时器
let pressTimer: number = 0; let pressTimer: number = 0;
// 重复执行定时器 // 重复执行定时器
let repeatTimer: number = 0; let repeatTimer: number = 0;
// 是否正在长按中
let isPressing = false;
/** /**
* 清除所有定时器 * 清除所有定时器
@@ -48,7 +48,7 @@ export const useLongPress = (): UseLongPress => {
repeatTimer = 0; repeatTimer = 0;
} }
// 重置长按状态 // 重置长按状态
isPressing = false; isPressing.value = false;
}; };
/** /**
@@ -69,7 +69,7 @@ export const useLongPress = (): UseLongPress => {
vibrate(1); vibrate(1);
// 设置长按状态 // 设置长按状态
isPressing = true; isPressing.value = true;
// 每100ms重复执行回调 // 每100ms重复执行回调
// @ts-ignore // @ts-ignore
repeatTimer = setInterval(() => { repeatTimer = setInterval(() => {