Forráskód Böngészése

feat: 出场页扫码枪监听——USB键盘快速输入自动识别ticket_no/车牌

lq 1 hónapja
szülő
commit
4b52efb623
1 módosított fájl, 22 hozzáadás és 1 törlés
  1. 22 1
      frontend/src/view/parking/entryExit.vue

+ 22 - 1
frontend/src/view/parking/entryExit.vue

@@ -131,7 +131,28 @@ onMounted(async () => {
   eventTimer = setInterval(pollEvents, 3000)
 })
 
-onUnmounted(() => { clearInterval(eventTimer) })
+	// 扫码枪监听
+	let scanBuf = '', scanTimer = null
+	function onScanKey(e) {
+	  if (e.target.tagName === 'INPUT') return
+	  if (e.key === 'Enter' && scanBuf.length >= 10) {
+	    const val = scanBuf.trim()
+	    if (/^[0-9a-f]{32}$/i.test(val)) queryForm.rfid_tag = val
+	    else queryForm.plate_number = val
+	    queryForm.rfid_tag || queryForm.plate_number ? queryVehicle() : null
+	    scanBuf = ''
+	  } else if (e.key.length === 1) {
+	    scanBuf += e.key; clearTimeout(scanTimer)
+	    scanTimer = setTimeout(() => { scanBuf = '' }, 80)
+	  }
+	}
+	document.addEventListener('keydown', onScanKey)
+
+	onUnmounted(() => {
+	  clearInterval(eventTimer)
+	  clearTimeout(scanTimer)
+	  document.removeEventListener('keydown', onScanKey)
+	})
 
 async function pollEvents() {
   try {