From 0ab6cdbb96d1efc00cbca105917aa021ad2491ef Mon Sep 17 00:00:00 2001 From: 南骏 池 <chiffly@163.com> Date: 星期二, 06 五月 2025 09:55:36 +0800 Subject: [PATCH] 1.新增扫描成功和失败音效。 --- H5/Js/Config.js | 83 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 79 insertions(+), 4 deletions(-) diff --git a/H5/Js/Config.js b/H5/Js/Config.js index d48bcbb..4eeffc6 100644 --- a/H5/Js/Config.js +++ b/H5/Js/Config.js @@ -3,7 +3,9 @@ data: function () { return { isLoading: false, - textInput:'' + textInput: '', + scanWorkstation: '', // 鏂板锛氭壂鎻忓伐浣嶇粦瀹氬瓧娈� + html5QrCode: null // 鏂板锛氭壂鐮佸櫒瀹炰緥 } }, mounted() { @@ -61,9 +63,82 @@ data: JSON.stringify(sendData) }) }, + // 淇敼sendScan鏂规硶涓哄疄闄呮壂鐮佸姛鑳� sendScan() { - var that = this; - that.$toast.fail("鏆傛椂涓嶈兘浣跨敤锛�"); + const that = this; + if (!this.html5QrCode) { + // 楦胯挋璁惧闇�瑕佷娇鐢ㄧ壒瀹氳澶嘔D + this.html5QrCode = new Html5Qrcode("qr-reader", { + experimentalFeatures: { + useBarCodeDetectorIfSupported: true + }, + formatsToSupport: [ Html5QrcodeSupportedFormats.QR_CODE ] + }); + } + + const config = { + fps: 10, + qrbox: 250, + // 楦胯挋闇�瑕佹槑纭寚瀹氳棰戣緭鍏ヨ澶� + videoConstraints: { + deviceId: 'default' // 浣跨敤榛樿鎽勫儚澶� + } + }; + + // 淇敼鎽勫儚澶磋皟鐢ㄦ柟寮� + this.html5QrCode.start( + config, + qrCodeMessage => { + that.scanWorkstation = qrCodeMessage; + that.stopScan(); + that.$toast.success("鎵爜鎴愬姛锛�"); + }, + errorMessage => { + console.error("鎵爜澶辫触:", errorMessage); + that.$toast.fail("鎵爜澶辫触"); + } + ).catch(err => { + console.error("鎽勫儚澶撮敊璇�:", err); + // 澧炲姞楦胯挋璁惧閿欒澶勭悊 + const errMsg = err.message || err.name || '鎽勫儚澶翠笉鍙敤'; + that.$toast.fail("鏃犳硶鍚姩鎽勫儚澶�: " + errMsg); + + // 鍘熺敓鎵爜澶囩敤鏂规 + if(window.plus && plus.barcode){ + plus.barcode.scan( + 'qr', + (type, result) => { + that.scanWorkstation = result; + that.$toast.success("鎵爜鎴愬姛锛�"); + }, + (error) => { + that.$toast.fail("鎵爜澶辫触: "+error.code); + } + ); + } + }); + + // 鏄剧ず鎵爜妗嗭紙闇�鍦ˋSPX涓坊鍔�<div id="qr-reader"></div>锛� + document.getElementById('qr-reader').style.display = 'block'; + }, + + // 鏂板锛氬仠姝㈡壂鐮佹柟娉� + stopScan() { + if (this.html5QrCode && this.html5QrCode.isScanning) { + this.html5QrCode.stop().then(() => { + document.getElementById('qr-reader').style.display = 'none'; + }).catch(err => { + console.error("鍏抽棴鎽勫儚澶村け璐�:", err); + }); + } + }, + + testSuccessSound() { + this.$playSound('success'); + }, + + testErrorSound() { + this.$playSound('error'); } } -}) \ No newline at end of file +}) -- Gitblit v1.9.3