dd2ebf863a
Security hardening: CORS lockdown, rate limiting middleware con sliding window e eviction IP stale, security headers (CSP, HSTS, X-Frame-Options), session cookie hardening, filename sanitization upload. i18n completion: internazionalizzati barcode.js e csv-export.js con bridge window.BARCODE_I18N/CSV_I18N, aggiornati .po IT/EN con 27 nuove stringhe. Tablet UX: touch target 44px per dispositivi coarse pointer. Test suite: 101 test totali (76 server + 25 client), copertura completa di tutti i router API, autenticazione, ruoli, CRUD, SPC, file upload, security integration. Infrastruttura SQLite async in-memory con fixtures. Fix critici: MissingGreenlet in recipe_service (selectinload eager), route ordering tasks.py, auth_service bcrypt diretto, Measurement.id Integer per SQLite. Documentazione: API.md (riferimento completo 40+ endpoint), DEPLOYMENT.md (guida produzione con Docker/Nginx/SSL), USER_GUIDE.md (manuale utente per ruolo). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
135 lines
3.2 KiB
JavaScript
135 lines
3.2 KiB
JavaScript
/**
|
|
* Barcode Scanner Manager
|
|
* Integration with html5-qrcode library
|
|
* Supports QR codes, barcodes, and camera scanning
|
|
*/
|
|
|
|
function barcodeScanner() {
|
|
const _t = (key) => (window.BARCODE_I18N && window.BARCODE_I18N[key]) || key;
|
|
|
|
return {
|
|
scanning: false,
|
|
result: null,
|
|
error: null,
|
|
scanner: null,
|
|
cameraId: null,
|
|
|
|
async startScan() {
|
|
this.scanning = true;
|
|
this.result = null;
|
|
this.error = null;
|
|
|
|
// Check library availability
|
|
if (!window.Html5Qrcode) {
|
|
this.error = _t('scanner_lib_not_loaded');
|
|
this.scanning = false;
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Get available cameras
|
|
const devices = await Html5Qrcode.getCameras();
|
|
|
|
if (!devices || devices.length === 0) {
|
|
this.error = _t('no_camera_available');
|
|
this.scanning = false;
|
|
return;
|
|
}
|
|
|
|
// Prefer back camera
|
|
const backCamera = devices.find(d => d.label.toLowerCase().includes('back'));
|
|
this.cameraId = backCamera ? backCamera.id : devices[0].id;
|
|
|
|
// Initialize scanner
|
|
this.scanner = new Html5Qrcode("barcode-reader");
|
|
|
|
// Start scanning
|
|
await this.scanner.start(
|
|
this.cameraId,
|
|
{
|
|
fps: 10,
|
|
qrbox: { width: 250, height: 250 },
|
|
aspectRatio: 1.0
|
|
},
|
|
(decodedText, decodedResult) => {
|
|
// Success callback
|
|
this.result = decodedText;
|
|
this.stopScan();
|
|
|
|
// Dispatch event for parent components
|
|
this.$dispatch('barcode-scanned', {
|
|
code: decodedText,
|
|
format: decodedResult.result?.format?.formatName || 'unknown',
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
},
|
|
(errorMessage) => {
|
|
// Error callback - ignore continuous scanning errors
|
|
// Only log non-routine errors
|
|
if (!errorMessage.includes('NotFoundException')) {
|
|
console.debug('Scan frame error:', errorMessage);
|
|
}
|
|
}
|
|
);
|
|
|
|
} catch (err) {
|
|
console.error('Scanner initialization error:', err);
|
|
this.error = _t('camera_access_error');
|
|
this.scanning = false;
|
|
}
|
|
},
|
|
|
|
async stopScan() {
|
|
if (this.scanner) {
|
|
try {
|
|
await this.scanner.stop();
|
|
await this.scanner.clear();
|
|
} catch (err) {
|
|
console.error('Stop scan error:', err);
|
|
}
|
|
this.scanner = null;
|
|
}
|
|
this.scanning = false;
|
|
},
|
|
|
|
clear() {
|
|
this.result = null;
|
|
this.error = null;
|
|
},
|
|
|
|
// Cleanup on component destroy
|
|
destroy() {
|
|
this.stopScan();
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Barcode Input Helper
|
|
* For integrating barcode scanning into input fields
|
|
*/
|
|
function barcodeInput() {
|
|
return {
|
|
value: '',
|
|
showScanner: false,
|
|
|
|
openScanner() {
|
|
this.showScanner = true;
|
|
},
|
|
|
|
handleScan(event) {
|
|
this.value = event.detail.code;
|
|
this.showScanner = false;
|
|
|
|
// Dispatch value change event
|
|
this.$dispatch('input', { value: this.value });
|
|
this.$dispatch('change', { value: this.value });
|
|
},
|
|
|
|
clear() {
|
|
this.value = '';
|
|
this.$dispatch('input', { value: '' });
|
|
}
|
|
};
|
|
}
|