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 |   87 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/H5/Js/Config.js b/H5/Js/Config.js
index ca234a3..4eeffc6 100644
--- a/H5/Js/Config.js
+++ b/H5/Js/Config.js
@@ -3,14 +3,16 @@
     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" +
@@ -20,7 +22,7 @@
                 // 鍙充笂瑙掓斁缃竴涓柟鍨嬩簩缁寸爜锛�80*80锛夛紝鎵弿鍚庣殑鍊间负鈥�123456鈥�
                 "BOX 560 10 640 90 2\r\n" + // 缁樺埗浜岀淮鐮佺殑鏂规
                 "TEXT 570 20 5 \"鏉$爜\"\r\n" + // 鍦ㄦ柟妗嗕腑涓婃柟鏄剧ず鈥滄潯鐮佲��
-                "QRCODE 570 40 M 4 U 0 \"123456\"\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" + // 鏄剧ず鏉″舰鐮佺殑浣嶇疆鍜屽ぇ灏�
@@ -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