Update templates/index.html
Browse files34 unmodified lines35363738394041424344454647481 unmodified line5051525354555657585960616 unmodified lines686970717273747576777879808134 unmodified lines</div><script>// 成功掃描後的回呼函式function onScanSuccess(decodedText, decodedResult) {console.log(`Scan result: ${decodedText}`);// 暫停掃描,避免重複送出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}`;// 更新下方列表 (簡單用 reload 演示,進階可用 DOM 操作)setTimeout(() => {window.location.reload();}, 1000);6 unmodified lines}function onScanFailure(error) {// 掃描失敗通常不需處理,因為每秒會嘗試很多次}// 初始化掃描器let html5QrcodeScanner = new Html5QrcodeScanner("reader",{ fps: 10, qrbox: {width: 250, height: 250} },/* verbose= */ false);html5QrcodeScanner.render(onScanSuccess, onScanFailure);</script>34 unmodified lines3536373839404142434445461 unmodified line484950515253545556576 unmodified lines6465666768697071727374757677787980818283848586878834 unmodified lines</div><script>function onScanSuccess(decodedText, decodedResult) {console.log(`Scan result: ${decodedText}`);// 暫停掃描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);6 unmodified lines}function onScanFailure(error) {// 這裡通常留空}// --- 這裡是最關鍵的修改 ---let html5QrcodeScanner = new Html5QrcodeScanner("reader",{fps: 10,qrbox: {width: 250, height: 250},// 加入這行:強制優先使用環境鏡頭 (後置鏡頭)videoConstraints: {facingMode: { exact: "environment" }}},/* verbose= */ false);// 備註:有些舊款 Android 對 'exact' 支援度不好,// 如果發現相機打不開,請將上面那行改成: facingMode: "environment" (拿掉 exact)html5QrcodeScanner.render(onScanSuccess, onScanFailure);</script>
templates/index.html+16-9