feat(reception): add multi-serial scanner for up to 4 COM ports and universal Argentine DNI parser (v3.8.52)
This commit is contained in:
@@ -76,23 +76,119 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Panel de Conexión Serial / Puerto COM (Web Serial API) -->
|
||||
<!-- Panel de Conexión Multi-Lector Serial / Puertos COM (Hasta 4 lectores) -->
|
||||
<div class="mt-4 pt-3 border-top">
|
||||
<div class="d-flex align-items-center justify-content-between mb-2">
|
||||
<span class="small fw-bold text-uppercase text-muted">
|
||||
<i class="bi bi-usb-symbol me-1 text-primary"></i> Puerto Serie (COM)
|
||||
</span>
|
||||
<span class="badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small" id="serialPortStatusBadge">
|
||||
<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> Puerto USB-HID Activo
|
||||
<i class="bi bi-usb-symbol me-1 text-primary"></i> Lectores Serie COM (Hasta 4)
|
||||
</span>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<span class="badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small" id="comGlobalBadge">
|
||||
<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> 0 / 4 Activos
|
||||
</span>
|
||||
<button type="button" class="btn btn-xs btn-link text-decoration-none p-0 text-muted" title="Reconectar autorizados" onclick="reconnectAuthorizedComPorts()">
|
||||
<i class="bi bi-arrow-clockwise"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between p-2 rounded-3 bg-body-tertiary border">
|
||||
<small class="text-muted" style="font-size: 0.74rem;">
|
||||
Dispositivos Seriales COM (Windows / Chromium)
|
||||
</small>
|
||||
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-3 py-1 text-nowrap" id="btnConnectSerial" onclick="handleSerialConnectClick()">
|
||||
<i class="bi bi-link-45deg me-1"></i>Configurar COM
|
||||
</button>
|
||||
|
||||
<!-- Grilla de los 4 Slots de Lectores Seriales -->
|
||||
<div class="row g-2" id="serialSlotsContainer">
|
||||
<!-- Slot 1 -->
|
||||
<div class="col-12">
|
||||
<div class="p-2 rounded-3 bg-body-tertiary border transition-all" id="slotCard1">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-secondary rounded-circle p-1" id="slotLed1" style="width: 10px; height: 10px;"></span>
|
||||
<div>
|
||||
<div class="fw-semibold small text-dark" style="font-size: 0.78rem;">Lector 1 (Paso Principal)</div>
|
||||
<div class="text-muted" style="font-size: 0.70rem;" id="slotStatusText1">Sin conectar</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<select class="form-select form-select-xs py-0 px-1 border-0 bg-transparent text-muted" id="slotBaud1" style="font-size: 0.70rem; width: 68px;">
|
||||
<option value="9600" selected>9600</option>
|
||||
<option value="115200">115200</option>
|
||||
</select>
|
||||
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-2 py-0" id="btnConnectSlot1" onclick="handleConnectSlot(1)" style="font-size: 0.72rem;">
|
||||
Conectar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Slot 2 -->
|
||||
<div class="col-12">
|
||||
<div class="p-2 rounded-3 bg-body-tertiary border transition-all" id="slotCard2">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-secondary rounded-circle p-1" id="slotLed2" style="width: 10px; height: 10px;"></span>
|
||||
<div>
|
||||
<div class="fw-semibold small text-dark" style="font-size: 0.78rem;">Lector 2 (Molinete / Acceso)</div>
|
||||
<div class="text-muted" style="font-size: 0.70rem;" id="slotStatusText2">Sin conectar</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<select class="form-select form-select-xs py-0 px-1 border-0 bg-transparent text-muted" id="slotBaud2" style="font-size: 0.70rem; width: 68px;">
|
||||
<option value="9600" selected>9600</option>
|
||||
<option value="115200">115200</option>
|
||||
</select>
|
||||
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-2 py-0" id="btnConnectSlot2" onclick="handleConnectSlot(2)" style="font-size: 0.72rem;">
|
||||
Conectar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Slot 3 -->
|
||||
<div class="col-12">
|
||||
<div class="p-2 rounded-3 bg-body-tertiary border transition-all" id="slotCard3">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-secondary rounded-circle p-1" id="slotLed3" style="width: 10px; height: 10px;"></span>
|
||||
<div>
|
||||
<div class="fw-semibold small text-dark" style="font-size: 0.78rem;">Lector 3 (Mesa Bedelía)</div>
|
||||
<div class="text-muted" style="font-size: 0.70rem;" id="slotStatusText3">Sin conectar</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<select class="form-select form-select-xs py-0 px-1 border-0 bg-transparent text-muted" id="slotBaud3" style="font-size: 0.70rem; width: 68px;">
|
||||
<option value="9600" selected>9600</option>
|
||||
<option value="115200">115200</option>
|
||||
</select>
|
||||
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-2 py-0" id="btnConnectSlot3" onclick="handleConnectSlot(3)" style="font-size: 0.72rem;">
|
||||
Conectar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Slot 4 -->
|
||||
<div class="col-12">
|
||||
<div class="p-2 rounded-3 bg-body-tertiary border transition-all" id="slotCard4">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-secondary rounded-circle p-1" id="slotLed4" style="width: 10px; height: 10px;"></span>
|
||||
<div>
|
||||
<div class="fw-semibold small text-dark" style="font-size: 0.78rem;">Lector 4 (Auxiliar / Puesto 2)</div>
|
||||
<div class="text-muted" style="font-size: 0.70rem;" id="slotStatusText4">Sin conectar</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-1">
|
||||
<select class="form-select form-select-xs py-0 px-1 border-0 bg-transparent text-muted" id="slotBaud4" style="font-size: 0.70rem; width: 68px;">
|
||||
<option value="9600" selected>9600</option>
|
||||
<option value="115200">115200</option>
|
||||
</select>
|
||||
<button type="button" class="btn btn-xs btn-outline-secondary rounded-pill px-2 py-0" id="btnConnectSlot4" onclick="handleConnectSlot(4)" style="font-size: 0.72rem;">
|
||||
Conectar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -218,87 +314,132 @@
|
||||
|
||||
<script>
|
||||
let isScanningLocked = false;
|
||||
let serialScanner = null;
|
||||
let multiScanner = null;
|
||||
|
||||
// Inicializar SerialBarcodeScanner para Chromium / Windows
|
||||
// Inicializar MultiSerialBarcodeScanner (hasta 4 lectores COM)
|
||||
function initSerialScanner() {
|
||||
if (typeof SerialBarcodeScanner === 'undefined') return;
|
||||
if (typeof MultiSerialBarcodeScanner === 'undefined') return;
|
||||
|
||||
serialScanner = new SerialBarcodeScanner({
|
||||
multiScanner = new MultiSerialBarcodeScanner({
|
||||
baudRate: 9600,
|
||||
onCodeScanned: function(code) {
|
||||
onCodeScanned: function(code, slotInfo) {
|
||||
if (!isScanningLocked) {
|
||||
isScanningLocked = true;
|
||||
playBeep(true);
|
||||
verifyToken(code);
|
||||
// Destello visual en la tarjeta del lector específico emisor
|
||||
flashSlotCard(slotInfo ? slotInfo.slotId : 1);
|
||||
verifyToken(code, slotInfo);
|
||||
setTimeout(() => { isScanningLocked = false; }, 1500);
|
||||
}
|
||||
},
|
||||
onStatusChanged: function(evt) {
|
||||
const badge = document.getElementById('serialPortStatusBadge');
|
||||
const btn = document.getElementById('btnConnectSerial');
|
||||
if (evt.status === 'CONNECTED') {
|
||||
if (badge) {
|
||||
badge.className = 'badge bg-success text-white rounded-pill px-2 py-1 small';
|
||||
badge.innerHTML = '<i class="bi bi-usb-plug-fill me-1"></i> COM Activo (9600 baud)';
|
||||
}
|
||||
if (btn) {
|
||||
btn.className = 'btn btn-xs btn-outline-danger rounded-pill px-3 py-1 text-nowrap';
|
||||
btn.innerHTML = '<i class="bi bi-x-circle me-1"></i>Desconectar';
|
||||
}
|
||||
} else {
|
||||
if (badge) {
|
||||
badge.className = 'badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small';
|
||||
badge.innerHTML = '<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> Puerto USB-HID Activo';
|
||||
}
|
||||
if (btn) {
|
||||
btn.className = 'btn btn-xs btn-outline-secondary rounded-pill px-3 py-1 text-nowrap';
|
||||
btn.innerHTML = '<i class="bi bi-link-45deg me-1"></i>Configurar COM';
|
||||
}
|
||||
}
|
||||
updateSlotUI(evt);
|
||||
},
|
||||
onError: function(err) {
|
||||
console.warn('[SerialScanner UI] Error:', err);
|
||||
onError: function(err, slot) {
|
||||
console.warn(`[MultiSerialScanner UI] Error en slot ${slot ? slot.id : '?'}:`, err);
|
||||
}
|
||||
});
|
||||
|
||||
// Comprobar soporte
|
||||
if (!serialScanner.isSupported()) {
|
||||
const badge = document.getElementById('serialPortStatusBadge');
|
||||
const btn = document.getElementById('btnConnectSerial');
|
||||
// Comprobar compatibilidad con Web Serial API
|
||||
if (!multiScanner.isSupported()) {
|
||||
const badge = document.getElementById('comGlobalBadge');
|
||||
if (badge) {
|
||||
badge.className = 'badge bg-body-tertiary text-muted rounded-pill px-2 py-1 small border';
|
||||
badge.textContent = 'Modo USB-HID (Chromium requerido para COM)';
|
||||
badge.innerHTML = '<i class="bi bi-info-circle me-1"></i> Modo USB-HID (Chromium requerido para COM)';
|
||||
}
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
const btn = document.getElementById(`btnConnectSlot${i}`);
|
||||
if (btn) btn.disabled = true;
|
||||
}
|
||||
if (btn) btn.disabled = true;
|
||||
} else {
|
||||
// Intentar auto-conexión a puerto previamente autorizado
|
||||
serialScanner.autoConnectIfAuthorized();
|
||||
// Reabrir automáticamente puertos autorizados
|
||||
reconnectAuthorizedComPorts();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSerialConnectClick() {
|
||||
if (!serialScanner) initSerialScanner();
|
||||
if (!serialScanner.isSupported()) {
|
||||
function updateSlotUI(evt) {
|
||||
const slotId = evt.slotId;
|
||||
const led = document.getElementById(`slotLed${slotId}`);
|
||||
const statusText = document.getElementById(`slotStatusText${slotId}`);
|
||||
const btn = document.getElementById(`btnConnectSlot${slotId}`);
|
||||
const globalBadge = document.getElementById('comGlobalBadge');
|
||||
|
||||
if (evt.status === 'CONNECTED') {
|
||||
if (led) led.className = 'badge bg-success rounded-circle p-1 animate-pulse-badge';
|
||||
if (statusText) {
|
||||
statusText.className = 'text-success fw-semibold';
|
||||
statusText.innerHTML = `<i class="bi bi-usb-plug-fill me-1"></i> COM Activo (${evt.baudRate || 9600} baud)`;
|
||||
}
|
||||
if (btn) {
|
||||
btn.className = 'btn btn-xs btn-outline-danger rounded-pill px-2 py-0';
|
||||
btn.innerHTML = '<i class="bi bi-x-circle me-1"></i>Desconectar';
|
||||
}
|
||||
} else {
|
||||
if (led) led.className = 'badge bg-secondary rounded-circle p-1';
|
||||
if (statusText) {
|
||||
statusText.className = 'text-muted';
|
||||
statusText.innerText = 'Sin conectar';
|
||||
}
|
||||
if (btn) {
|
||||
btn.className = 'btn btn-xs btn-outline-secondary rounded-pill px-2 py-0';
|
||||
btn.innerText = 'Conectar';
|
||||
}
|
||||
}
|
||||
|
||||
if (globalBadge) {
|
||||
const connected = evt.totalConnected !== undefined ? evt.totalConnected : (multiScanner ? multiScanner.getConnectedCount() : 0);
|
||||
if (connected > 0) {
|
||||
globalBadge.className = 'badge bg-success text-white rounded-pill px-2 py-1 small shadow-xs';
|
||||
globalBadge.innerHTML = `<i class="bi bi-check-circle-fill me-1"></i> ${connected} / 4 Activos`;
|
||||
} else {
|
||||
globalBadge.className = 'badge bg-secondary-subtle text-secondary rounded-pill px-2 py-1 small';
|
||||
globalBadge.innerHTML = '<i class="bi bi-circle-fill text-muted me-1" style="font-size: 0.5rem;"></i> 0 / 4 Activos';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function flashSlotCard(slotId) {
|
||||
const card = document.getElementById(`slotCard${slotId}`);
|
||||
if (!card) return;
|
||||
card.classList.add('border-primary', 'bg-primary-subtle');
|
||||
setTimeout(() => {
|
||||
card.classList.remove('border-primary', 'bg-primary-subtle');
|
||||
}, 800);
|
||||
}
|
||||
|
||||
async function handleConnectSlot(slotId) {
|
||||
if (!multiScanner) initSerialScanner();
|
||||
if (!multiScanner.isSupported()) {
|
||||
alert('La Web Serial API no está disponible en este navegador. Utiliza Google Chrome o Microsoft Edge en entornos Windows.');
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('btnConnectSerial');
|
||||
if (serialScanner.port) {
|
||||
await serialScanner.disconnect();
|
||||
const slot = multiScanner.getSlot(slotId);
|
||||
if (slot && slot.isConnected()) {
|
||||
await multiScanner.disconnectSlot(slotId);
|
||||
} else {
|
||||
const baudSelect = document.getElementById(`slotBaud${slotId}`);
|
||||
const baudRate = baudSelect ? parseInt(baudSelect.value, 10) : 9600;
|
||||
try {
|
||||
await serialScanner.requestAndConnect(9600);
|
||||
await multiScanner.requestAndConnectSlot(slotId, baudRate);
|
||||
} catch (err) {
|
||||
if (err.name !== 'NotFoundError') {
|
||||
console.error('Error al conectar puerto COM:', err);
|
||||
alert('No se pudo abrir el puerto serie: ' + err.message);
|
||||
console.error(`Error conectando slot ${slotId}:`, err);
|
||||
alert(`No se pudo abrir el puerto serie para el Lector ${slotId}: ` + err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function reconnectAuthorizedComPorts() {
|
||||
if (!multiScanner) initSerialScanner();
|
||||
if (multiScanner && multiScanner.isSupported()) {
|
||||
const count = await multiScanner.autoConnectAuthorizedPorts();
|
||||
if (count > 0) {
|
||||
console.log(`[MultiSerialScanner] ${count} puertos reconectados automáticamente.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mantener el cursor forzado permanentemente en el input de la pistola óptica
|
||||
function focusScannerInput() {
|
||||
const input = document.getElementById('scannerInput');
|
||||
@@ -342,7 +483,7 @@
|
||||
}
|
||||
|
||||
// Petición AJAX de verificación al Backend BFF
|
||||
async function verifyToken(token) {
|
||||
async function verifyToken(token, slotInfo = null) {
|
||||
const buildingId = document.getElementById('buildingSelect').value;
|
||||
|
||||
try {
|
||||
@@ -356,7 +497,7 @@
|
||||
});
|
||||
|
||||
const data = await resp.json();
|
||||
displayVerificationResult(data);
|
||||
displayVerificationResult(data, slotInfo);
|
||||
refreshRecentLogs();
|
||||
} catch (err) {
|
||||
console.error('Error verificando:', err);
|
||||
@@ -364,14 +505,14 @@
|
||||
status: 'DENEGADO',
|
||||
message: 'Error de conexión con el validador.',
|
||||
todays_classes: []
|
||||
});
|
||||
}, slotInfo);
|
||||
} finally {
|
||||
setTimeout(focusScannerInput, 150);
|
||||
}
|
||||
}
|
||||
|
||||
// Despliegue visual de resultados en pantalla
|
||||
function displayVerificationResult(data) {
|
||||
function displayVerificationResult(data, slotInfo = null) {
|
||||
const waitingState = document.getElementById('waitingState');
|
||||
const activeState = document.getElementById('activeResultState');
|
||||
const resultCard = document.getElementById('resultCard');
|
||||
@@ -392,8 +533,10 @@
|
||||
void resultCard.offsetWidth; // Forzar reflow para reiniciar animación
|
||||
|
||||
if (alertBadge) {
|
||||
const sourceLabel = slotInfo ? (slotInfo.slotName || `Lector ${slotInfo.slotId}`) : 'Pistola Óptica';
|
||||
alertBadge.innerHTML = `<i class="bi bi-lightning-charge-fill text-warning me-1"></i> ¡Nuevo Escaneo! <span class="badge bg-dark text-white ms-1 fw-normal">${sourceLabel}</span>`;
|
||||
alertBadge.classList.remove('d-none');
|
||||
setTimeout(() => { alertBadge.classList.add('d-none'); }, 2500);
|
||||
setTimeout(() => { alertBadge.classList.add('d-none'); }, 3000);
|
||||
}
|
||||
|
||||
const hasClasses = Boolean(data.todays_classes && data.todays_classes.length > 0);
|
||||
@@ -474,6 +617,20 @@
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
} else if (data.status === 'DENEGADO') {
|
||||
classesContainer.innerHTML = `
|
||||
<div class="alert alert-danger border border-danger-subtle text-danger-emphasis p-3 rounded-4 mb-0 shadow-xs">
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<div class="rounded-circle bg-danger text-white p-2 d-flex align-items-center justify-content-center shadow-xs" style="width: 42px; height: 42px;">
|
||||
<i class="bi bi-shield-x fs-5"></i>
|
||||
</div>
|
||||
<div>
|
||||
<div class="fw-bold fs-6">Ingreso No Autorizado</div>
|
||||
<div class="small">${data.message || 'El documento o credencial escaneada no registra permisos vigentes de ingreso.'}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
classesContainer.innerHTML = `
|
||||
<div class="alert alert-warning border border-warning-subtle text-dark p-3 rounded-4 mb-0 shadow-xs">
|
||||
|
||||
Reference in New Issue
Block a user