فهرست منبع

微信支付码被扫重复监听的问题修改

licc 3 هفته پیش
والد
کامیت
03ec76227e
1فایلهای تغییر یافته به همراه13 افزوده شده و 8 حذف شده
  1. 13 8
      src/views/order/console.vue

+ 13 - 8
src/views/order/console.vue

@@ -488,17 +488,18 @@ const confirmSubmit = () => {
 
 // 添加扫码事件监听函数
 const handleScanInput = (event: KeyboardEvent) => {
+
+  console.log("event.key", event.key)
   if (event.key === 'Enter') {
-    const code = scanCode.value
-    console.log('扫码内容:', code)
+    document.removeEventListener('keydown', handleScanInput)
     if (!data.canScan) {
       feedback.notifyWarning('正在处理支付,请勿重复扫码')
       return
     }
-    data.canScan = false
+    const code = scanCode.value
+    console.log('扫码内容:', code)
     payingDialogVisible.value = true // 显示支付中对话框
 
-    document.removeEventListener('keydown', handleScanInput)
     // 修改支付处理逻辑
     orderPay({ oid: params.number, code: code })
         .then((res) => {
@@ -525,16 +526,18 @@ const handleScanInput = (event: KeyboardEvent) => {
           }
         })
         .catch((e) => {
-          console.log(e)
+          console.log("=====---", e)
           // 支付失败
           payingDialogVisible.value = false // 隐藏支付中对话框
-          feedback.confirm('支付失败,请重试').then(() => {
+          feedback.notifySuccess('支付失败,请重试')
             data.canScan = true
             scanDialogVisible.value = true
             // 添加键盘事件监听
-            document.addEventListener('keydown', handleScanInput)
+            setTimeout(()=>{
+              document.removeEventListener('keydown', handleScanInput)
+              document.addEventListener('keydown', handleScanInput)
+            }, 2000)
           })
-        })
     scanCode.value = ''
   } else {
     scanCode.value += event.key
@@ -617,6 +620,8 @@ const checkout = () => {
     data.canScan = true
     scanDialogVisible.value = true
     // 添加键盘事件监听
+
+    document.removeEventListener('keydown', handleScanInput)
     document.addEventListener('keydown', handleScanInput)
     // })
 }