Update templates/index.html
Browse files2 unmodified lines345667891010111213141516171819202116222324252627282930313226332829303435333637363738394041424338394041424344455046474849505152535455565758592 unmodified lines626364596566676364686970711 unmodified line737475727374757677781 unmodified line8081828383848585868788899091919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134951351361373 unmodified lines1411421431051441071451461471111121131481491151161171501511191521531541231241551561571581291301311321331591601611621631641391401411421431441451651661671681692 unmodified lines<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>智慧盤點系統</title> <title>智慧盤點系統 V2</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: #f4f7f6; color: #333; } h2 { text-align: center; color: #333; margin-bottom: 20px; } h2 { text-align: center; color: #333; margin-bottom: 10px; } /* 管理區塊樣式 */ .admin-panel { background: #e9ecef; padding: 10px 15px; border-radius: 8px; margin-bottom: 20px; font-size: 0.9em; border: 1px solid #ced4da; } .admin-panel summary { cursor: pointer; font-weight: bold; color: #495057; } .upload-box { margin-top: 10px; display: flex; gap: 10px; align-items: center; } .db-status { font-size: 0.8em; color: #666; margin-top: 5px; }
/* 掃描器 */ #reader-container { display: none; margin-bottom: 20px; animation: fadeIn 0.5s; } #reader { width: 100%; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 15px 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: 14px 28px; border-radius: 50px; font-weight: bold; cursor: pointer; border: none; font-size: 1rem; width: 100%; max-width: 280px; text-align: center; transition: all 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .btn:active { transform: scale(0.98); } .btn-start { background: linear-gradient(135deg, #007bff, #0056b3); color: white; } .btn-stop { background: linear-gradient(135deg, #dc3545, #a71d2a); color: white; display: none; } .btn-download { background: linear-gradient(135deg, #28a745, #1e7e34); color: white; text-decoration: none; display: flex; justify-content: center; align-items: center; } .btn-upload { background: #6c757d; color: white; padding: 5px 15px; border-radius: 4px; font-size: 0.9em; width: auto; box-shadow: none; }
/* 結果列表 */ .result-area { background: white; padding: 0 20px; border-radius: 16px; box-shadow: 0 4px 20px 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 #f0f0f0; padding: 15px 0; display: flex; justify-content: space-between; align-items: center; } /* 重點:讓商品名稱變大 */ .log-info { display: flex; flex-direction: column; } .product-name { font-size: 1.1em; font-weight: 700; color: #2c3e50; } .product-code { font-size: 0.85em; color: #999; margin-top: 4px; font-family: monospace;} .log-time { font-size: 0.8em; color: #aaa; white-space: nowrap; }
/* 成功提示框 */ .success-msg { background: #d1e7dd; color: #0f5132; padding: 15px; border-radius: 12px; text-align: center; margin-top: 15px; display: none; border: 1px solid #badbcc; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } .success-msg strong { display: block; font-size: 1.2em; margin-top: 5px; } /* 提示框 */ .success-msg { background: #d1e7dd; color: #0f5132; padding: 15px; border-radius: 12px; text-align: center; margin-top: 15px; display: none; border: 1px solid #badbcc; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } } </style></head><body>
<h2>📦 智慧對照盤點系統</h2> <h2>📦 智慧盤點系統</h2>
<details class="admin-panel"> <summary>⚙️ 設定:上傳商品對照表 CSV</summary> <div class="upload-box"> <input type="file" id="csv-file" accept=".csv" /> <button onclick="uploadCSV()" class="btn btn-upload">上傳更新</button> </div> <p class="db-status">目前資料庫內有 <strong id="db-count">{{ db_count }}</strong> 筆商品資料</p> <p style="font-size:0.8em; color:#888;">CSV 格式:第一欄條碼,第二欄名稱 (請存為 UTF-8)</p> </details> <div class="action-area"> <button onclick="startScanner()" id="btn-start" class="btn btn-start">📷 啟動相機</button>2 unmodified lines
<div id="reader-container"> <div id="reader"></div> <p style="text-align: center; color: #888; font-size: 0.9em; margin-top:10px;">請將條碼/QR Code 置於框內</p> </div> <div id="status-msg" class="success-msg"> ✅ 掃描成功 <strong id="msg-product-name">商品名稱</strong> ✅ 掃描成功 <strong id="msg-product-name">商品名稱</strong> </div>
<div class="action-area">1 unmodified line </div>
<div class="result-area"> <div class="result-header"> <span>物品資訊</span> <span>時間</span> </div> <div id="log-list"> {% for record in records %} <div class="log-item">1 unmodified line <span class="product-name" style="{{ 'color:red' if record.name == '未知物品' else '' }}"> {{ record.name }} </span> <span class="product-code">{{ record.content }}</span> <div class="product-code">{{ record.content }}</div> </div> <span class="log-time">{{ record.time.split(' ')[1] }}</span> </div> <span class="log-time">{{ record.time.split(' ')[1] }}</span> </div> {% endfor %} </div> </div>
<script> let html5QrcodeScanner = null; // --- 上傳 CSV 的功能 --- function uploadCSV() { const fileInput = document.getElementById('csv-file'); if (fileInput.files.length === 0) { alert("請先選擇 CSV 檔案!"); return; }
const formData = new FormData(); formData.append("file", fileInput.files[0]);
const btn = document.querySelector('.btn-upload'); btn.innerText = "上傳中..."; btn.disabled = true;
fetch('/api/upload_csv', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if(data.status === 'success') { alert(data.message); document.getElementById('db-count').innerText = data.count; fileInput.value = ''; // 清空選擇 } else { alert("上傳失敗"); } }) .catch(error => { console.error('Error:', error); alert("上傳發生錯誤"); }) .finally(() => { btn.innerText = "上傳更新"; btn.disabled = false; }); }
// --- 掃描功能 --- let html5QrcodeScanner = null; function onScanSuccess(decodedText, decodedResult) { if(html5QrcodeScanner) html5QrcodeScanner.pause(); fetch('/api/scan', { method: 'POST', headers: { 'Content-Type': 'application/json' },3 unmodified lines .then(data => { const msg = document.getElementById('status-msg'); const nameSpan = document.getElementById('msg-product-name'); msg.style.display = 'block'; // 這裡顯示回傳的「名稱」 nameSpan.innerText = data.data.name; if(data.data.name === "未知物品"){ msg.style.background = "#f8d7da"; msg.style.color = "#842029"; msg.style.borderColor = "#f5c2c7"; msg.style.background = "#f8d7da"; msg.style.color = "#842029"; msg.style.borderColor = "#f5c2c7"; } else { msg.style.background = "#d1e7dd"; msg.style.color = "#0f5132"; msg.style.borderColor = "#badbcc"; msg.style.background = "#d1e7dd"; msg.style.color = "#0f5132"; msg.style.borderColor = "#badbcc"; }
setTimeout(() => { window.location.reload(); }, 1200); }) .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 ]; const formats = [Html5QrcodeSupportedFormats.QR_CODE, Html5QrcodeSupportedFormats.EAN_13, Html5QrcodeSupportedFormats.EAN_8, Html5QrcodeSupportedFormats.CODE_128, Html5QrcodeSupportedFormats.CODE_39, Html5QrcodeSupportedFormats.UPC_A];
function startScanner() { document.getElementById('reader-container').style.display = 'block'; document.getElementById('btn-start').style.display = 'none'; document.getElementById('btn-stop').style.display = 'block'; document.getElementById('status-msg').style.display = 'none'; // 隱藏舊訊息
html5QrcodeScanner = new Html5QrcodeScanner( "reader", { fps: 10, qrbox: {width: 250, height: 200}, videoConstraints: { facingMode: "environment" }, formatsToSupport: formats }, false ); document.getElementById('status-msg').style.display = 'none'; html5QrcodeScanner = new Html5QrcodeScanner("reader", { fps: 10, qrbox: {width: 250, height: 200}, videoConstraints: { facingMode: "environment" }, formatsToSupport: formats }, false); html5QrcodeScanner.render(onScanSuccess, (error) => {}); }
templates/index.html+72-51