-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
73 lines (65 loc) · 2.18 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Controle Refeitório</title>
</head>
<body>
<h1>Controle Refeitório</h1>
<video id="video" width="300" height="200" autoplay></video>
<p id="output">QR Code não escaneado.</p>
<button id="enviar">Registrar Presença</button>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jsQR.js"></script>
<script>
const video = document.getElementById('video');
const output = document.getElementById('output');
const enviarButton = document.getElementById('enviar');
let qrCodeData = null;
// Acessar a câmera
navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } })
.then((stream) => {
video.srcObject = stream;
video.play();
scanQRCode();
});
function scanQRCode() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
setInterval(() => {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const code = jsQR(imageData.data, canvas.width, canvas.height);
if (code) {
qrCodeData = code.data;
output.textContent = `QR Code lido: ${qrCodeData}`;
}
}, 500);
}
enviarButton.addEventListener('click', () => {
if (!qrCodeData) {
alert('Escaneie um QR Code antes de enviar.');
return;
}
// Enviar dados ao backend
fetch('http://127.0.0.1:5000/registrar', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ qrData: qrCodeData }),
})
.then(response => response.json())
.then(data => {
alert(data.message);
})
.catch(error => {
alert('Erro ao registrar presença.');
console.error(error);
});
});
</script>
</body>
</html>