feat(kiosco): pantalla de QR rotativo + perilla de rotación en el panel
- kiosco.html: la asistente entra con la cuenta de supervisora y muestra un QR que rota cada rotacion_seg (POST /api/kiosco/qr). El QR codifica la URL a /checada.html?t=<token>; el becario lo escanea con su teléfono y su sesión pone la identidad. Estado "checado cerrado" fuera de ventana. QR vía qrcodejs (cdnjs), componentes cream de theme.js. - Dockerfile: hornea kiosco.html en la imagen (nginx ya lo sirve por try_files). - panel.html: en Configuración, perilla "Rotación del QR (segundos)" (10–300) y botón "Abrir pantalla de kiosco". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f52cc9738
commit
e761d5d0e0
3 files changed
+185
-3
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ COPY --chown=node:node backend/src ./src
|
||||
# stat/leer los archivos; copiar con `--chmod=644 … /dir/` deja el propio
|
||||
# directorio en 0644 y nginx falla con "Permission denied". Por eso se fijan
|
||||
# los permisos explícitamente después del COPY.
|
||||
COPY frontend/checada.html frontend/panel.html frontend/becario.html frontend/theme.js frontend/logo-taboada.png /usr/share/nginx/html/
|
||||
COPY frontend/checada.html frontend/panel.html frontend/becario.html frontend/kiosco.html frontend/theme.js frontend/logo-taboada.png /usr/share/nginx/html/
|
||||
RUN chmod 755 /usr/share/nginx/html && chmod 644 /usr/share/nginx/html/*
|
||||
COPY --chmod=644 backend/nginx-default.conf /etc/nginx/http.d/default.conf
|
||||
COPY --chmod=755 backend/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Taboada — Kiosco</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700&family=Figtree:wght@400;500;600;700&display=swap" rel="stylesheet"/>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
|
||||
<script src="theme.js"></script>
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; }
|
||||
body { background: #F3EBDD; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
|
||||
input::placeholder { color: #B4A99A; }
|
||||
@keyframes tb-spin { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="text/babel" data-presets="react">
|
||||
const { useState, useEffect, useRef, useCallback } = React;
|
||||
|
||||
// Pantalla de kiosco (vector de presencia por QR). La abre la asistente en su
|
||||
// teléfono con la cuenta de supervisora (misma cookie/guardia que el panel).
|
||||
// Muestra un QR rotativo; el becario lo escanea con SU teléfono y aterriza en
|
||||
// /checada.html?t=<token>, donde su propia sesión pone la identidad.
|
||||
const { apiFetch } = Theme;
|
||||
const UI = Theme.makeUI("checada"); // piel cream móvil
|
||||
const { Logo, Card, Btn, Input, Aviso, Estado, palette, fonts, icons } = UI;
|
||||
|
||||
const Shell = ({ children }) => (
|
||||
<div style={{ minHeight: "100vh", background: palette.bgGradient, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "28px 20px", fontFamily: fonts.body }}>
|
||||
<div style={{ width: "100%", maxWidth: "420px" }}>
|
||||
<div style={{ display: "flex", justifyContent: "center", marginBottom: "22px" }}><Logo /></div>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const Cargando = ({ texto = "Cargando…" }) => (
|
||||
<Card style={{ textAlign: "center" }}>
|
||||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: "12px" }}>
|
||||
<span style={{ display: "inline-flex" }}>{icons.spinner({ size: 24, color: palette.primary, track: palette.line })}</span>
|
||||
<span style={{ fontFamily: fonts.body, fontSize: "14px", color: palette.inkSoft }}>{texto}</span>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
// ═══════════════ Login de la asistente (cuenta de supervisora) ═══════════════
|
||||
function Login({ onEntra }) {
|
||||
const [f, setF] = useState({ usuario: "", password: "" });
|
||||
const [error, setError] = useState(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const submit = async (e) => {
|
||||
e.preventDefault(); setBusy(true); setError(null);
|
||||
try {
|
||||
await apiFetch("/auth/login", { method: "POST", body: JSON.stringify(f) });
|
||||
onEntra(await apiFetch("/auth/session"));
|
||||
} catch (err) {
|
||||
setError(err.status === 429 ? { text: "Demasiados intentos, espera un minuto.", ic: "clock" }
|
||||
: { text: "Usuario o contraseña incorrectos.", ic: "alertCircle" });
|
||||
} finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Card>
|
||||
<h2 style={{ margin: "0 0 4px", fontFamily: fonts.title, fontWeight: 600, letterSpacing: "-.01em", color: palette.ink, fontSize: "22px", textAlign: "center" }}>Abrir kiosco</h2>
|
||||
<p style={{ margin: "0 0 18px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "13px", textAlign: "center" }}>Inicia sesión para mostrar el código de checada.</p>
|
||||
{error && <Aviso variant="error" icon={error.ic}>{error.text}</Aviso>}
|
||||
<form onSubmit={submit}>
|
||||
<div style={{ marginBottom: "12px" }}>
|
||||
<Input placeholder="Usuario" value={f.usuario} onChange={(e) => setF({ ...f, usuario: e.target.value })} autoComplete="username" required />
|
||||
</div>
|
||||
<div style={{ marginBottom: "16px" }}>
|
||||
<Input type="password" placeholder="Contraseña" value={f.password} onChange={(e) => setF({ ...f, password: e.target.value })} autoComplete="current-password" required />
|
||||
</div>
|
||||
<Btn type="submit" loading={busy} disabled={busy || !f.usuario || !f.password}>{busy ? "Entrando…" : "Entrar"}</Btn>
|
||||
</form>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ═══════════════ Kiosco: QR rotativo ═══════════════
|
||||
function Kiosco({ onSalir }) {
|
||||
const [estado, setEstado] = useState(undefined); // undefined=cargando · {cerrado,token,rotacion_seg,...}
|
||||
const [error, setError] = useState(null);
|
||||
const qrHost = useRef(null); // div donde qrcodejs pinta
|
||||
const qrObj = useRef(null); // instancia QRCode
|
||||
const timer = useRef(null);
|
||||
|
||||
// Pide un token nuevo al servidor. 401 → sesión caída, vuelve al login.
|
||||
const emitir = useCallback(async () => {
|
||||
try {
|
||||
const r = await apiFetch("/kiosco/qr", { method: "POST" });
|
||||
setError(null); setEstado(r);
|
||||
} catch (err) {
|
||||
if (err.status === 401) { onSalir(); return; }
|
||||
setError(err.status === 429 ? "Demasiadas solicitudes; espera un momento." : "No se pudo generar el código. Reintentando…");
|
||||
}
|
||||
}, [onSalir]);
|
||||
|
||||
useEffect(() => { emitir(); }, [emitir]);
|
||||
|
||||
// Reprograma la siguiente emisión según la rotación que devuelve el servidor.
|
||||
// El token viejo sigue válido hasta su expiración (validez = rotacion×2), así
|
||||
// que quien escanee justo en el cambio no se queda con un QR muerto.
|
||||
useEffect(() => {
|
||||
if (!estado) return;
|
||||
const secs = estado.rotacion_seg || 45;
|
||||
timer.current = setTimeout(emitir, secs * 1000);
|
||||
return () => clearTimeout(timer.current);
|
||||
}, [estado, emitir]);
|
||||
|
||||
// Repinta el QR cuando cambia el token (URL absoluta a /checada.html?t=…).
|
||||
useEffect(() => {
|
||||
if (!estado || estado.cerrado || !estado.token || !qrHost.current) return;
|
||||
const url = `${window.location.origin}/checada.html?t=${estado.token}`;
|
||||
if (!qrObj.current) {
|
||||
qrObj.current = new QRCode(qrHost.current, { text: url, width: 264, height: 264, correctLevel: QRCode.CorrectLevel.M });
|
||||
} else {
|
||||
qrObj.current.clear();
|
||||
qrObj.current.makeCode(url);
|
||||
}
|
||||
}, [estado]);
|
||||
|
||||
if (estado === undefined) return <Shell><Cargando texto="Generando código…" /></Shell>;
|
||||
|
||||
if (estado.cerrado) return (
|
||||
<Shell>
|
||||
<Estado icon="clock" tone="amber" title="Checado cerrado"
|
||||
sub={`Fuera del horario de operación (${estado.ventana?.inicio}–${estado.ventana?.fin}). El código volverá al abrir la ventana.`}
|
||||
action={<Btn variant="ghost" onClick={onSalir}>Cerrar kiosco</Btn>} />
|
||||
</Shell>
|
||||
);
|
||||
|
||||
return (
|
||||
<Shell>
|
||||
<Card style={{ textAlign: "center" }}>
|
||||
<h2 style={{ margin: "0 0 4px", fontFamily: fonts.title, fontWeight: 600, letterSpacing: "-.01em", color: palette.ink, fontSize: "22px" }}>Escanea para checar</h2>
|
||||
<p style={{ margin: "0 0 18px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "13px" }}>Acerca tu teléfono y escanea este código con la cámara.</p>
|
||||
<div style={{ display: "flex", justifyContent: "center", marginBottom: "16px" }}>
|
||||
<div ref={qrHost} style={{ display: "inline-block", padding: "16px", background: "#fff", borderRadius: "18px", border: `1px solid ${palette.cardBorder}`, lineHeight: 0 }} />
|
||||
</div>
|
||||
{error && <Aviso variant="error" icon="alertCircle">{error}</Aviso>}
|
||||
<p style={{ margin: "0 0 16px", fontFamily: fonts.body, color: palette.inkSoft, fontSize: "12px" }}>
|
||||
El código cambia cada {estado.rotacion_seg}s. Cada uno sirve una sola vez.
|
||||
</p>
|
||||
<Btn variant="ghost" onClick={onSalir}>Cerrar kiosco</Btn>
|
||||
</Card>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [session, setSession] = useState(undefined);
|
||||
useEffect(() => { apiFetch("/auth/session").then(setSession).catch(() => setSession(null)); }, []);
|
||||
const salir = async () => { try { await apiFetch("/auth/logout", { method: "POST" }); } catch {} setSession(null); };
|
||||
if (session === undefined) return <Shell><Cargando texto="Verificando sesión…" /></Shell>;
|
||||
if (!session) return <Login onEntra={setSession} />;
|
||||
return <Kiosco onSalir={salir} />;
|
||||
}
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+15
-2
@@ -438,7 +438,7 @@ function VistaBecario({ becarioId, onBack, onError }) {
|
||||
// ═══════════════════ Configuración ═══════════════════
|
||||
function VistaConfig({ onError }) {
|
||||
const [cfg, setCfg] = useState(null);
|
||||
const [f, setF] = useState({ inicio: "", fin: "", tarea_activa: false, meta: "" });
|
||||
const [f, setF] = useState({ inicio: "", fin: "", tarea_activa: false, meta: "", qr_rotacion: "" });
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [okMsg, setOkMsg] = useState(null);
|
||||
const load = useCallback(async () => {
|
||||
@@ -450,6 +450,7 @@ function VistaConfig({ onError }) {
|
||||
fin: c.ventana_horaria?.fin || "20:00",
|
||||
tarea_activa: c.tarea_activa === true,
|
||||
meta: c.meta_horas_default ?? 480,
|
||||
qr_rotacion: c.qr_rotacion_seg ?? 45,
|
||||
});
|
||||
} catch (e) { onError(e.message); }
|
||||
}, [onError]);
|
||||
@@ -461,6 +462,7 @@ function VistaConfig({ onError }) {
|
||||
ventana_horaria: { inicio: f.inicio, fin: f.fin },
|
||||
tarea_activa: f.tarea_activa,
|
||||
meta_horas_default: Number(f.meta),
|
||||
qr_rotacion_seg: Number(f.qr_rotacion),
|
||||
}) });
|
||||
setOkMsg("Configuración guardada."); await load();
|
||||
} catch (err) { onError(err.message); } finally { setBusy(false); }
|
||||
@@ -481,8 +483,19 @@ function VistaConfig({ onError }) {
|
||||
<Toggle checked={f.tarea_activa} onChange={(v) => setF({ ...f, tarea_activa: v })} label="Pedir el concepto de la tarea al checar (switch global)" />
|
||||
</div>
|
||||
<Field label="Meta de horas por defecto"><Input type="number" min="1" value={f.meta} onChange={(e) => setF({ ...f, meta: e.target.value })} style={{ maxWidth: "160px" }} /></Field>
|
||||
|
||||
<div style={{ borderTop: `1px solid ${palette.line}`, margin: "6px 0 14px" }} />
|
||||
<div style={{ fontFamily: fonts.body, fontWeight: 600, fontSize: "14px", color: palette.ink, marginBottom: "5px" }}>Kiosco de checada (QR)</div>
|
||||
<p style={{ margin: "0 0 14px", fontFamily: fonts.body, fontSize: "12px", color: palette.inkSoft, lineHeight: 1.5 }}>Cada cuánto rota el código del kiosco. La validez de cada código es el doble de este valor (colchón para quien escanea en el cambio).</p>
|
||||
<Field label="Rotación del QR (segundos)"><Input type="number" min="10" max="300" value={f.qr_rotacion} onChange={(e) => setF({ ...f, qr_rotacion: e.target.value })} style={{ maxWidth: "160px" }} /></Field>
|
||||
|
||||
{okMsg && <Aviso variant="success" icon="check">{okMsg}</Aviso>}
|
||||
<div style={{ marginTop: "6px" }}><Btn type="submit" loading={busy} disabled={busy}>{busy ? "Guardando…" : "Guardar configuración"}</Btn></div>
|
||||
<div style={{ marginTop: "6px", display: "flex", gap: "9px", flexWrap: "wrap" }}>
|
||||
<Btn type="submit" loading={busy} disabled={busy}>{busy ? "Guardando…" : "Guardar configuración"}</Btn>
|
||||
<a href="/kiosco.html" target="_blank" rel="noopener" style={{ textDecoration: "none" }}>
|
||||
<Btn variant="outline">Abrir pantalla de kiosco ↗</Btn>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user