Update templates/index.html
Browse files73 unmodified lines747576777879808182831 unmodified line85868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212373 unmodified lines<script>function onScanSuccess(decodedText, decodedResult) {// 暫停掃描,避免連拍html5QrcodeScanner.pause();// 發送資料fetch('/api/scan', {method: 'POST',headers: { 'Content-Type': 'application/json' },1 unmodified line}).then(response => response.json()).then(data => {// 顯示成功訊息const msg = document.getElementById('status-msg');msg.style.display = 'block';msg.innerText = `✅ 已紀錄:${data.data.content}`;// 1秒後重新整理頁面以顯示最新數據setTimeout(() => {window.location.reload();}, 1000);}).catch((error) => {console.error('Error:', error);alert('紀錄失敗,請檢查網路');html5QrcodeScanner.resume();});}// 初始化掃描器 (強制使用後鏡頭)let html5QrcodeScanner = new Html5QrcodeScanner("reader",{fps: 10,qrbox: {width: 250, height: 250},videoConstraints: {facingMode: "environment"}},false);html5QrcodeScanner.render(onScanSuccess, (error) => {// 掃描失敗不做處理,避免 console 被洗版});</script></body></html>73 unmodified lines74757677787980811 unmodified line838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013173 unmodified lines<script>function onScanSuccess(decodedText, decodedResult) {html5QrcodeScanner.pause();fetch('/api/scan', {method: 'POST',headers: { 'Content-Type': 'application/json' },1 unmodified line}).then(response => response.json()).then(data => {const msg = document.getElementById('status-msg');msg.style.display = 'block';// 這裡顯示掃到的內容 (條碼通常是數字)msg.innerText = `✅ 已紀錄:${data.data.content}`;setTimeout(() => {window.location.reload();}, 1000);}).catch((error) => {console.error('Error:', error);alert('紀錄失敗');html5QrcodeScanner.resume();});}// --- 設定支援的格式 ---const formats = [Html5QrcodeSupportedFormats.QR_CODE, // QR CodeHtml5QrcodeSupportedFormats.EAN_13, // 常見商品條碼 (長條)Html5QrcodeSupportedFormats.EAN_8, // 短版商品條碼Html5QrcodeSupportedFormats.CODE_128, // 物流/快遞單常見Html5QrcodeSupportedFormats.CODE_39, // 工業/識別證常見Html5QrcodeSupportedFormats.UPC_A, // 美國商品常見Html5QrcodeSupportedFormats.UPC_E];let html5QrcodeScanner = new Html5QrcodeScanner("reader",{fps: 10,// 為了適應長條形的 Barcode,我們可以把掃描框設寬一點,或者維持方形也可以qrbox: {width: 280, height: 200},videoConstraints: {facingMode: "environment"},// 加入這行:指定支援的格式formatsToSupport: formats},false);html5QrcodeScanner.render(onScanSuccess, (error) => {});</script></body></html>
templates/index.html+19-11