以下是修改后的代码:
<view class="flex flex-direction">
<button class="cu-btn lg margin-tb-sm"
:class="isRecording ? 'bg-red' : 'bg-blue'"
@touchstart="handleTouchStart"
@touchend="stopRecording"
style="height: 80px;">
<text class="cuIcon-voice"></text>
{{isRecording ? '松开结束' : '按住不放开始'}}
</button>
</view> 然后在你的JavaScript/Vue方法部分添加以下代码:
data() {
return {
isRecording: false,
lastTouchTime: 0,
touchThreshold: 300 // 设置触发间隔阈值,单位毫秒
}
},
methods: {
handleTouchStart(e) {
const now = Date.now();
// 检查距离上次触发的时间是否超过阈值
if (now - this.lastTouchTime > this.touchThreshold) {
this.lastTouchTime = now;
this.startRecording(e);
}
},
startRecording(e) {
// 原来的录音开始逻辑
if (!this.isRecording) {
this.isRecording = true;
// 其他录音开始代码...
}
},
stopRecording(e) {
// 录音结束逻辑
if (this.isRecording) {
this.isRecording = false;
// 其他录音结束代码...
}
}
} 解决方案说明添加了一个新的方法 handleTouchStart 来处理 touchstart 事件使用时间戳来跟踪上次触发的时间设置了一个阈值(这里是300毫秒),只有当两次触发的间隔大于这个阈值时,才会真正执行录音开始的逻辑这样可以有效防止用户快速点击导致的多次触发问题你可以根据实际需求调整 touchThreshold 的值,使其更适合你的应用场景。
网友回复
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?
linux上如何运行任意windows程序?
ai能写出比黑客还厉害的零日漏洞等攻击工具攻击任意软件系统工程?
js如何获取浏览器的音频上下文指纹、Canvas指纹、WebGL渲染特征?
为啥ai开始抛弃markdown文本,重新偏好html文本了?
网站有没有办法鉴别访问请求是由ai操控chrome-devtools-mcp发出的?


