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 | 129 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 122 insertions(+), 7 deletions(-) diff --git a/H5/Js/Config.js b/H5/Js/Config.js index c74cc32..4eeffc6 100644 --- a/H5/Js/Config.js +++ b/H5/Js/Config.js @@ -3,17 +3,59 @@ data: function () { return { isLoading: false, - textInput:'' + textInput: '', + scanWorkstation: '', // 鏂板锛氭壂鎻忓伐浣嶇粦瀹氬瓧娈� + html5QrCode: null // 鏂板锛氭壂鐮佸櫒瀹炰緥 } }, mounted() { var that = this; }, methods: { - sendMessage() { + sendMessage(obj) { + var detail = ["绗竴缁勬寚浠�"+ + "! 0 203 203 480 1\r\n" + + "PREFEED 0\n\r" + + "POSTFEED 0\n\r" + + "PAGE - WIDTH 640\r\n" + + + // 鍙充笂瑙掓斁缃竴涓柟鍨嬩簩缁寸爜锛�80*80锛夛紝鎵弿鍚庣殑鍊间负鈥�123456鈥� + "BOX 560 10 640 90 2\r\n" + // 缁樺埗浜岀淮鐮佺殑鏂规 + "TEXT 570 20 5 \"鏉$爜\"\r\n" + // 鍦ㄦ柟妗嗕腑涓婃柟鏄剧ず鈥滄潯鐮佲�� + "QRCODE 570 40 M 4 U 0 \"" + obj.qrcode+"\"\r\n" + // 鍒涘缓浜岀淮鐮� + + // 鍙充笅瑙掓樉绀轰竴涓潯褰㈢爜锛屾渶宸﹀湪320浣嶇疆锛岄暱搴︿负100锛屽悓鏃惰繖涓潯褰㈢爜灏嗗叾鎵弿鐨勫�兼樉绀哄湪鏉″舰鐮佷笅渚э紝鏉″舰鐮佺殑鍊间负鈥�987654鈥� + "BARCODE 320 350 100 50 1 \"987654\"\r\n" + // 鏄剧ず鏉″舰鐮佺殑浣嶇疆鍜屽ぇ灏� + "TEXT 320 410 5 \"987654\"\r\n" + // + "GAP-SENSE\r\n" + + "ENDQR\r\n" + + "FORM\r\n" + + "PRINT\r\n", + "绗簩缁勬寚浠�" + "! 0 400 400 480 1\r\n" + + "PREFEED 0\n\r" + + "POSTFEED 0\n\r" + + "PAGE - WIDTH 640\r\n" + + "GAP-SENSE\r\n" + + "BOX 5 10 620 450 2\r\n" + + "LINE 5 60 620 60 1\r\n" + // 妯嚎1 + "LINE 5 110 620 110 1\r\n" + // 妯嚎2 + "LINE 5 160 620 160 1\r\n" + // 妯嚎3 + "LINE 5 210 620 210 1\r\n" + // 妯嚎4 + "LINE 5 260 620 260 1\r\n" + // 妯嚎5 + "LINE 120 10 120 260 1\r\n" + // 瀛楁鍚嶇О鍙充晶绔栫嚎 + "LINE 240 260 240 450 1\r\n" + // 瑙勬牸鍨嬪彿宸︿晶绔栫嚎 + "LINE 285 210 285 450 1\r\n" + // 瑙勬牸鍨嬪彿鍙充晶绔栫嚎 + "LINE 410 210 410 260 1\r\n" + // 鍒拌揣鏃ユ湡鍙充晶绔栫嚎 + "ENDQR\r\n" + + "FORM\r\n" + + "PRINT\r\n" ]; + let sendData = { - keyType: 'print', - keyVal: '123', + Type: 'Bar', + Barcode: 'TM250304-000104-2', + Detail: detail, + Ip: '192.168.38.25', + Port: '9100', } console.log('sendMessage 寮�濮�1:') console.log('sendMessage 寮�濮�2:' + JSON.stringify(sendData)) @@ -21,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