// 用户点名JavaScript - 支持服务器和本地双模式 // 状态管理 let currentList = null; let stream = null; // DOM元素 const inputSection = document.getElementById('inputSection'); const rollCallSection = document.getElementById('rollCallSection'); const enterForm = document.getElementById('enterForm'); const codeInput = document.getElementById('codeInput'); const scanQRBtn = document.getElementById('scanQRBtn'); const completedCount = document.getElementById('completedCount'); const totalCount = document.getElementById('totalCount'); const progressFill = document.getElementById('progressFill'); const memberListDisplay = document.getElementById('memberListDisplay'); const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); const startCameraBtn = document.getElementById('startCameraBtn'); const captureBtn = document.getElementById('captureBtn'); const stopCameraBtn = document.getElementById('stopCameraBtn'); const capturedPhoto = document.getElementById('capturedPhoto'); const photoPreview = document.getElementById('photoPreview'); const confirmPhotoBtn = document.getElementById('confirmPhotoBtn'); const retakeBtn = document.getElementById('retakeBtn'); const manualSelect = document.getElementById('manualSelect'); const manualRollCallBtn = document.getElementById('manualRollCallBtn'); // 初始化 document.addEventListener('DOMContentLoaded', () => { // 显示运行模式 const modeText = dataStorage.isServerMode ? '服务器模式' : '本地模式'; const modeIndicator = document.getElementById('modeIndicator'); if (modeIndicator) { modeIndicator.textContent = `当前运行模式: ${modeText}`; if (!dataStorage.isServerMode) { modeIndicator.textContent += ' (数据保存在浏览器本地)'; } } console.log(`点名系统运行在: ${modeText}`); // 检查URL参数 const urlParams = new URLSearchParams(window.location.search); const codeFromUrl = urlParams.get('code'); if (codeFromUrl) { codeInput.value = codeFromUrl; enterRollCall(codeFromUrl); } }); // 进入点名 enterForm.addEventListener('submit', (e) => { e.preventDefault(); const code = codeInput.value.trim(); enterRollCall(code); }); async function enterRollCall(code) { try { currentList = await dataStorage.getList(code); inputSection.style.display = 'none'; rollCallSection.style.display = 'block'; updateProgress(); renderMemberList(); populateManualSelect(); } catch (error) { alert('进入点名失败:' + error.message); } } // 扫描二维码(简化版) scanQRBtn.addEventListener('click', () => { alert('扫码功能需要集成摄像头扫码库,当前版本请手动输入编号'); }); // 更新进度 function updateProgress() { if (!currentList) return; const completed = currentList.members.filter(m => m.completed).length; const total = currentList.members.length; const percentage = total > 0 ? (completed / total * 100) : 0; completedCount.textContent = completed; totalCount.textContent = total; progressFill.style.width = percentage + '%'; progressFill.textContent = Math.round(percentage) + '%'; } // 渲染成员列表 function renderMemberList() { if (!currentList) return; memberListDisplay.innerHTML = currentList.members.map((member, index) => `