diff --git a/src/main/resources/views/platform/zhghh5/scan/index.html b/src/main/resources/views/platform/zhghh5/scan/index.html index 45beba1..d78bfbc 100644 --- a/src/main/resources/views/platform/zhghh5/scan/index.html +++ b/src/main/resources/views/platform/zhghh5/scan/index.html @@ -115,6 +115,7 @@ layout("/layouts/platform_h5.html"){ @@ -196,12 +197,20 @@ layout("/layouts/platform_h5.html"){ this.scanStatus = true; try { + const container = document.getElementById('reader'); + const size = Math.min(container.clientWidth * 0.8, 300); // 最大 300px await this.html5QrCode.start( cameraId, { - fps: 300, - qrbox: { width: 300, height: 300 }, - aspectRatio: 1.0 + fps: 10, + qrbox: size, + videoConstraints: { + width: { ideal: 1280 }, + height: { ideal: 720 }, + facingMode: "environment" // 强制后置(部分浏览器支持) + }, + disableFlip: true, // 防止镜像 + formatsToSupport: [Html5QrcodeSupportedFormats.QR_CODE] // 只扫 QR,提升速度 }, (decodedText) => { this.decodedText = decodedText @@ -221,11 +230,18 @@ layout("/layouts/platform_h5.html"){ async closeScan() { if (!this.html5QrCode || !this.scanStatus) return; try { + const videoEl = this.html5QrCode?.getState()?.camera?.stream?.getVideoTracks(); + if (videoEl && videoEl.length) { + videoEl.forEach(track => track.stop()); + } await this.html5QrCode.stop(); - this.scanStatus = false; - this.html5QrCode = null; } catch (err) { console.error('关闭失败:', err); + }finally { + this.scanStatus = false; + this.html5QrCode = null; + const reader = document.getElementById('reader'); + if (reader) reader.innerHTML = ''; } },