Update templates/index.html
Browse files2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940417 unmodified lines49505152535455565758596061626364657 unmodified lines73747576777879804 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301312 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>QR Code 盤點系統</title><script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script><style>body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; padding: 20px; max-width: 600px; margin: 0 auto; background: #f0f2f5; color: #333; }h2 { text-align: center; color: #1a1a1a; margin-bottom: 20px; }/* 掃描器樣式 */#reader { width: 100%; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); background: #000; }/* 按鈕區域 */.action-area { display: flex; justify-content: center; margin: 20px 0; }.btn-download {background-color: #2ecc71;color: white;padding: 12px 24px;text-decoration: none;border-radius: 50px;font-weight: bold;box-shadow: 0 2px 4px rgba(0,0,0,0.2);display: flex;align-items: center;gap: 8px;transition: transform 0.1s;}.btn-download:active { transform: scale(0.95); }/* 列表樣式 */.result-area { background: white; padding: 0 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }.result-header { border-bottom: 2px solid #f0f0f0; padding: 15px 0; font-weight: bold; color: #666; display: flex; justify-content: space-between; }.log-item { border-bottom: 1px solid #eee; padding: 15px 0; display: flex; justify-content: space-between; align-items: center; }.log-item:last-child { border-bottom: none; }.log-content { font-size: 1.1em; font-weight: 500; }.log-time { font-size: 0.85em; color: #888; }/* 成功提示 */.success-msg {7 unmodified lines<h2>📦 盤點與點名系統</h2><div id="reader"></div><p id="status-msg" class="success-msg">✅ 掃描成功!</p><div class="action-area"><a href="/download" class="btn-download">📥 下載今日紀錄 (.csv)</a></div><div class="result-area"><div class="result-header"><span>掃描內容</span><span>時間</span></div><div id="log-list">7 unmodified lines</div><script>function onScanSuccess(decodedText, decodedResult) {html5QrcodeScanner.pause();fetch('/api/scan', {method: 'POST',4 unmodified lines.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>2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748497 unmodified lines575859606162636465666768697071727374757677787980817 unmodified lines89909192939495969798991001014 unmodified lines1061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701712 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>QR Code & Barcode 盤點系統</title><script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script><style>body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; padding: 20px; max-width: 600px; margin: 0 auto; background: #f0f2f5; color: #333; }h2 { text-align: center; color: #1a1a1a; margin-bottom: 20px; }/* 掃描器樣式 - 預設隱藏 */#reader-container {display: none; /* 關鍵:預設不顯示 */margin-bottom: 20px;}#reader { width: 100%; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); background: #000; }/* 按鈕區域 */.action-area { display: flex; flex-direction: column; align-items: center; gap: 15px; margin: 20px 0; }.btn {padding: 12px 24px;text-decoration: none;border-radius: 50px;font-weight: bold;box-shadow: 0 2px 4px rgba(0,0,0,0.2);cursor: pointer;border: none;font-size: 1rem;width: 100%;max-width: 250px;text-align: center;}.btn-start { background-color: #007bff; color: white; }.btn-stop { background-color: #dc3545; color: white; display: none; } /* 預設隱藏 */.btn-download { background-color: #2ecc71; color: white; display: flex; justify-content: center; align-items: center; gap: 8px;}/* 列表樣式 */.result-area { background: white; padding: 0 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }.result-header { border-bottom: 2px solid #f0f0f0; padding: 15px 0; font-weight: bold; color: #666; display: flex; justify-content: space-between; }.log-item { border-bottom: 1px solid #eee; padding: 15px 0; display: flex; justify-content: space-between; align-items: center; }.log-item:last-child { border-bottom: none; }.log-content { font-size: 1.1em; font-weight: 500; word-break: break-all; } /* 防止長條碼撐破版面 */.log-time { font-size: 0.85em; color: #888; white-space: nowrap; margin-left: 10px;}/* 成功提示 */.success-msg {7 unmodified lines<h2>📦 盤點與點名系統</h2><div class="action-area"><button onclick="startScanner()" id="btn-start" class="btn btn-start">📷 開始掃描</button><button onclick="stopScanner()" id="btn-stop" class="btn btn-stop">❌ 關閉鏡頭</button></div><div id="reader-container"><div id="reader"></div><p style="text-align: center; color: #666; font-size: 0.9em;">若掃描不清楚,請調整距離或點擊畫面重新對焦</p></div><p id="status-msg" class="success-msg">✅ 掃描成功!</p><div class="action-area"><a href="/download" class="btn btn-download">📥 下載紀錄 (.csv)</a></div><div class="result-area"><div class="result-header"><span>內容</span><span>時間</span></div><div id="log-list">7 unmodified lines</div><script>let html5QrcodeScanner = null;function onScanSuccess(decodedText, decodedResult) {// 暫停掃描if(html5QrcodeScanner) {html5QrcodeScanner.pause();}fetch('/api/scan', {method: 'POST',4 unmodified lines.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('紀錄失敗,請檢查網路');if(html5QrcodeScanner) html5QrcodeScanner.resume();});}// 定義支援的條碼格式const formats = [Html5QrcodeSupportedFormats.QR_CODE,Html5QrcodeSupportedFormats.EAN_13,Html5QrcodeSupportedFormats.EAN_8,Html5QrcodeSupportedFormats.CODE_128,Html5QrcodeSupportedFormats.CODE_39,Html5QrcodeSupportedFormats.UPC_A,Html5QrcodeSupportedFormats.UPC_E];// 啟動掃描器的函式function startScanner() {// 顯示掃描區域與停止按鈕document.getElementById('reader-container').style.display = 'block';document.getElementById('btn-start').style.display = 'none';document.getElementById('btn-stop').style.display = 'block';// 初始化並渲染html5QrcodeScanner = new Html5QrcodeScanner("reader",{fps: 10,qrbox: {width: 250, height: 200},videoConstraints: { facingMode: "environment" },formatsToSupport: formats},false);html5QrcodeScanner.render(onScanSuccess, (error) => {});}// 手動停止掃描的函式function stopScanner() {if (html5QrcodeScanner) {html5QrcodeScanner.clear().then(() => {// 隱藏區域,恢復開始按鈕document.getElementById('reader-container').style.display = 'none';document.getElementById('btn-start').style.display = 'block';document.getElementById('btn-stop').style.display = 'none';html5QrcodeScanner = null;}).catch(error => {console.error("Failed to clear html5QrcodeScanner. ", error);});}}</script></body></html>
templates/index.html+82-42