631 lines
22 KiB
TypeScript
631 lines
22 KiB
TypeScript
// ==============================================================================
|
|
// Vista de Inicio de Sesión de Operador / Guardia (OnEverControl Web)
|
|
// Paridad Visual 1:1 con la versión de escritorio de OneverAccess (login_window.py)
|
|
// Sistema de Diseño OnEver con Ola Gradiente (Indigo/Blue), Pills inputs y Glassmorphism
|
|
// ==============================================================================
|
|
import React, { useState, useEffect } from 'react';
|
|
import { useAuth } from '../context/AuthContext';
|
|
import { workstationApi, WorkstationListItem } from '../api/workstationApi';
|
|
import { useTheme } from '../hooks/useTheme';
|
|
import { APP_VERSION, APP_BUILD } from '../version';
|
|
|
|
export const LoginView: React.FC = () => {
|
|
const { login, workstation, setWorkstation } = useAuth();
|
|
const { theme, toggleTheme } = useTheme();
|
|
|
|
const [username, setUsername] = useState<string>(() => {
|
|
return localStorage.getItem('on_ever_username') || 'guardia';
|
|
});
|
|
const [password, setPassword] = useState<string>('');
|
|
const [showPassword, setShowPassword] = useState<boolean>(false);
|
|
const [rememberMe, setRememberMe] = useState<boolean>(() => {
|
|
const saved = localStorage.getItem('on_ever_remember_me');
|
|
return saved !== null ? saved === 'true' : true;
|
|
});
|
|
const [selectedWks, setSelectedWks] = useState<string>(workstation || 'CFT-DESK');
|
|
const [availableWorkstations, setAvailableWorkstations] = useState<WorkstationListItem[]>([]);
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
|
|
|
const isDark = theme === 'dark';
|
|
|
|
useEffect(() => {
|
|
// Carga de Workstations reales desde SQL Server
|
|
workstationApi
|
|
.getAvailableWorkstations()
|
|
.then((list) => {
|
|
if (list && list.length > 0) {
|
|
setAvailableWorkstations(list);
|
|
const currentMatch = list.find(
|
|
(w) => w.name.toUpperCase() === (workstation || 'CFT-DESK').toUpperCase()
|
|
);
|
|
if (currentMatch) {
|
|
setSelectedWks(currentMatch.name);
|
|
} else {
|
|
setSelectedWks(list[0].name);
|
|
}
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.warn('No se pudieron listar estaciones desde DB:', err);
|
|
});
|
|
}, [workstation]);
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!username.trim() || !password) {
|
|
setErrorMsg('Ingrese usuario y contraseña');
|
|
return;
|
|
}
|
|
|
|
setIsLoading(true);
|
|
setErrorMsg(null);
|
|
|
|
try {
|
|
setWorkstation(selectedWks);
|
|
await login(username.trim(), password, selectedWks, rememberMe);
|
|
} catch (err: any) {
|
|
setErrorMsg(err.message || 'Credenciales inválidas. Verifique usuario o contraseña.');
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const toggleFullscreen = () => {
|
|
if (!document.fullscreenElement) {
|
|
document.documentElement.requestFullscreen().catch(() => {});
|
|
} else {
|
|
document.exitFullscreen().catch(() => {});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
minHeight: '100%',
|
|
backgroundColor: isDark ? '#090D16' : '#F1F5F9',
|
|
backgroundImage: isDark
|
|
? 'radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 60%)'
|
|
: 'radial-gradient(circle at 50% 0%, rgba(14, 165, 233, 0.12) 0%, transparent 60%)',
|
|
padding: '1.5rem',
|
|
position: 'relative',
|
|
userSelect: 'none',
|
|
}}
|
|
>
|
|
{/* Botones Flotantes de Utilidades (Tema y Pantalla Completa) */}
|
|
<div
|
|
style={{
|
|
position: 'absolute',
|
|
top: '1.25rem',
|
|
right: '1.25rem',
|
|
display: 'flex',
|
|
gap: '0.5rem',
|
|
zIndex: 10,
|
|
}}
|
|
>
|
|
<button
|
|
type="button"
|
|
onClick={toggleTheme}
|
|
style={{
|
|
minHeight: '38px',
|
|
padding: '0 0.85rem',
|
|
fontSize: '0.85rem',
|
|
backgroundColor: isDark ? 'rgba(30, 41, 59, 0.85)' : 'rgba(255, 255, 255, 0.9)',
|
|
color: isDark ? '#F8FAFC' : '#0F172A',
|
|
border: `1px solid ${isDark ? '#334155' : '#CBD5E1'}`,
|
|
borderRadius: '19px',
|
|
cursor: 'pointer',
|
|
backdropFilter: 'blur(8px)',
|
|
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.4rem',
|
|
fontWeight: 600,
|
|
}}
|
|
title="Cambiar tema OnEver (Oscuro / Claro)"
|
|
>
|
|
<span>{isDark ? '☀️' : '🌙'}</span>
|
|
<span>{isDark ? 'Claro' : 'Oscuro'}</span>
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={toggleFullscreen}
|
|
style={{
|
|
minHeight: '38px',
|
|
width: '38px',
|
|
padding: 0,
|
|
fontSize: '1rem',
|
|
backgroundColor: isDark ? 'rgba(30, 41, 59, 0.85)' : 'rgba(255, 255, 255, 0.9)',
|
|
color: isDark ? '#F8FAFC' : '#0F172A',
|
|
border: `1px solid ${isDark ? '#334155' : '#CBD5E1'}`,
|
|
borderRadius: '50%',
|
|
cursor: 'pointer',
|
|
backdropFilter: 'blur(8px)',
|
|
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
}}
|
|
title="Pantalla Completa"
|
|
>
|
|
⛶
|
|
</button>
|
|
</div>
|
|
|
|
{/* Tarjeta de Login (Paridad con LoginBackgroundFrame de OneverAccess Desktop) */}
|
|
<div
|
|
style={{
|
|
width: '100%',
|
|
maxWidth: '440px',
|
|
backgroundColor: isDark ? '#0F172A' : '#FFFFFF',
|
|
borderRadius: '24px',
|
|
border: `1px solid ${isDark ? '#1E293B' : '#E2E8F0'}`,
|
|
boxShadow: isDark
|
|
? '0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(99, 102, 241, 0.1)'
|
|
: '0 25px 50px -12px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(14, 165, 233, 0.1)',
|
|
position: 'relative',
|
|
overflow: 'hidden',
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
}}
|
|
>
|
|
{/* Onda Decorativa Superior con Gradiente Curvo (Idéntica a LoginBackgroundFrame) */}
|
|
<div
|
|
style={{
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
height: '165px',
|
|
overflow: 'hidden',
|
|
pointerEvents: 'none',
|
|
zIndex: 1,
|
|
}}
|
|
>
|
|
<svg
|
|
viewBox="0 0 440 165"
|
|
preserveAspectRatio="none"
|
|
style={{ width: '100%', height: '100%', display: 'block' }}
|
|
>
|
|
<defs>
|
|
<linearGradient id="loginWaveGrad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
{isDark ? (
|
|
<>
|
|
<stop offset="0%" stopColor="#6366f1" /> {/* Indigo */}
|
|
<stop offset="100%" stopColor="#3b82f6" /> {/* Blue */}
|
|
</>
|
|
) : (
|
|
<>
|
|
<stop offset="0%" stopColor="#8b5cf6" /> {/* Purple */}
|
|
<stop offset="100%" stopColor="#0ea5e9" /> {/* Light Blue */}
|
|
</>
|
|
)}
|
|
</linearGradient>
|
|
</defs>
|
|
{/* Curva Bezier cúbica idéntica al painter.cubicTo de PyQt6 */}
|
|
<path
|
|
d="M 0 0 L 0 135 C 154 85, 286 160, 440 115 L 440 0 Z"
|
|
fill="url(#loginWaveGrad)"
|
|
/>
|
|
</svg>
|
|
</div>
|
|
|
|
{/* Contenido Principal del Formulario */}
|
|
<div
|
|
style={{
|
|
padding: '2.5rem 2.25rem 2rem',
|
|
position: 'relative',
|
|
zIndex: 2,
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
}}
|
|
>
|
|
{/* Logo Corporativo OneverAccess */}
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
marginBottom: '2.5rem',
|
|
height: '110px',
|
|
}}
|
|
>
|
|
<img
|
|
src={isDark ? '/logo_login_dark.png' : '/logo_login_light.png'}
|
|
alt="OnEver Access"
|
|
style={{
|
|
maxHeight: '85px',
|
|
maxWidth: '280px',
|
|
width: 'auto',
|
|
objectFit: 'contain',
|
|
filter: 'drop-shadow(0 4px 8px rgba(0,0,0,0.25))',
|
|
}}
|
|
onError={(e) => {
|
|
(e.target as HTMLImageElement).src = '/logo_mini.png';
|
|
}}
|
|
/>
|
|
</div>
|
|
|
|
{/* Formulario */}
|
|
<form
|
|
onSubmit={handleSubmit}
|
|
style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}
|
|
>
|
|
{/* Puesto de Control / Workstation (Pill Shape) */}
|
|
<div>
|
|
<label
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.4rem',
|
|
fontSize: '0.75rem',
|
|
fontWeight: 700,
|
|
color: isDark ? '#94A3B8' : '#64748B',
|
|
marginBottom: '0.4rem',
|
|
letterSpacing: '0.05em',
|
|
textTransform: 'uppercase',
|
|
paddingLeft: '0.75rem',
|
|
}}
|
|
>
|
|
<span>🖥️</span> Puesto de Control (Workstation)
|
|
</label>
|
|
<select
|
|
value={selectedWks}
|
|
onChange={(e) => setSelectedWks(e.target.value)}
|
|
style={{
|
|
width: '100%',
|
|
height: '46px',
|
|
borderRadius: '23px',
|
|
backgroundColor: isDark ? '#1E293B' : '#F8FAFC',
|
|
border: `1px solid ${isDark ? '#374151' : '#CBD5E1'}`,
|
|
color: isDark ? '#F8FAFC' : '#0F172A',
|
|
padding: '0 20px',
|
|
fontSize: '0.9rem',
|
|
fontWeight: 600,
|
|
outline: 'none',
|
|
cursor: 'pointer',
|
|
appearance: 'auto',
|
|
}}
|
|
>
|
|
{availableWorkstations.length > 0 ? (
|
|
availableWorkstations.map((w) => (
|
|
<option key={w.id} value={w.name}>
|
|
{w.name} (ID {w.id})
|
|
</option>
|
|
))
|
|
) : (
|
|
<option value="CFT-DESK">CFT-DESK (ID 100001)</option>
|
|
)}
|
|
</select>
|
|
</div>
|
|
|
|
{/* Campo Usuario (Pill Shape) */}
|
|
<div>
|
|
<label
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.4rem',
|
|
fontSize: '0.75rem',
|
|
fontWeight: 700,
|
|
color: isDark ? '#94A3B8' : '#64748B',
|
|
marginBottom: '0.4rem',
|
|
letterSpacing: '0.05em',
|
|
textTransform: 'uppercase',
|
|
paddingLeft: '0.75rem',
|
|
}}
|
|
>
|
|
<span>👤</span> Usuario
|
|
</label>
|
|
<input
|
|
id="username"
|
|
name="username"
|
|
autoComplete="username"
|
|
type="text"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
placeholder="Username"
|
|
autoCapitalize="none"
|
|
autoCorrect="off"
|
|
required
|
|
style={{
|
|
width: '100%',
|
|
height: '46px',
|
|
borderRadius: '23px',
|
|
backgroundColor: isDark ? '#1E293B' : '#F8FAFC',
|
|
border: `1px solid ${isDark ? '#374151' : '#CBD5E1'}`,
|
|
color: isDark ? '#F8FAFC' : '#0F172A',
|
|
padding: '0 20px',
|
|
fontSize: '0.925rem',
|
|
fontWeight: 500,
|
|
outline: 'none',
|
|
transition: 'border-color 0.2s, box-shadow 0.2s',
|
|
}}
|
|
onFocus={(e) => {
|
|
e.currentTarget.style.borderColor = '#2563EB';
|
|
e.currentTarget.style.boxShadow = '0 0 0 3px rgba(37, 99, 235, 0.2)';
|
|
}}
|
|
onBlur={(e) => {
|
|
e.currentTarget.style.borderColor = isDark ? '#374151' : '#CBD5E1';
|
|
e.currentTarget.style.boxShadow = 'none';
|
|
}}
|
|
/>
|
|
</div>
|
|
|
|
{/* Campo Contraseña con Botón de Ojo (Pill Shape) */}
|
|
<div>
|
|
<label
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.4rem',
|
|
fontSize: '0.75rem',
|
|
fontWeight: 700,
|
|
color: isDark ? '#94A3B8' : '#64748B',
|
|
marginBottom: '0.4rem',
|
|
letterSpacing: '0.05em',
|
|
textTransform: 'uppercase',
|
|
paddingLeft: '0.75rem',
|
|
}}
|
|
>
|
|
<span>🔒</span> Contraseña
|
|
</label>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
height: '46px',
|
|
borderRadius: '23px',
|
|
backgroundColor: isDark ? '#1E293B' : '#F8FAFC',
|
|
border: `1px solid ${isDark ? '#374151' : '#CBD5E1'}`,
|
|
overflow: 'hidden',
|
|
transition: 'border-color 0.2s, box-shadow 0.2s',
|
|
}}
|
|
id="passwordContainer"
|
|
>
|
|
<input
|
|
id="password"
|
|
name="password"
|
|
autoComplete="current-password"
|
|
type={showPassword ? 'text' : 'password'}
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="Password"
|
|
required
|
|
style={{
|
|
flex: 1,
|
|
height: '100%',
|
|
border: 'none',
|
|
backgroundColor: 'transparent',
|
|
color: isDark ? '#F8FAFC' : '#0F172A',
|
|
padding: '0 0 0 20px',
|
|
fontSize: '0.925rem',
|
|
fontWeight: 500,
|
|
outline: 'none',
|
|
}}
|
|
onFocus={() => {
|
|
const el = document.getElementById('passwordContainer');
|
|
if (el) {
|
|
el.style.borderColor = '#2563EB';
|
|
el.style.boxShadow = '0 0 0 3px rgba(37, 99, 235, 0.2)';
|
|
}
|
|
}}
|
|
onBlur={() => {
|
|
const el = document.getElementById('passwordContainer');
|
|
if (el) {
|
|
el.style.borderColor = isDark ? '#374151' : '#CBD5E1';
|
|
el.style.boxShadow = 'none';
|
|
}
|
|
}}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
style={{
|
|
height: '100%',
|
|
width: '46px',
|
|
border: 'none',
|
|
backgroundColor: 'transparent',
|
|
color: isDark ? '#94A3B8' : '#64748B',
|
|
fontSize: '1.1rem',
|
|
cursor: 'pointer',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
paddingRight: '6px',
|
|
transition: 'color 0.15s',
|
|
}}
|
|
title={showPassword ? 'Ocultar contraseña' : 'Ver contraseña'}
|
|
>
|
|
{showPassword ? '👁️' : '🔒'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Checkbox: Recordar sesión y permanecer conectado (PWA / Tablets) */}
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
padding: '0.1rem 0.6rem',
|
|
}}
|
|
>
|
|
<label
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.55rem',
|
|
cursor: 'pointer',
|
|
fontSize: '0.84rem',
|
|
color: isDark ? '#94A3B8' : '#475569',
|
|
userSelect: 'none',
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={rememberMe}
|
|
onChange={(e) => setRememberMe(e.target.checked)}
|
|
style={{
|
|
width: '18px',
|
|
height: '18px',
|
|
accentColor: '#2563EB',
|
|
cursor: 'pointer',
|
|
}}
|
|
/>
|
|
<span style={{ fontWeight: 600 }}>Permanecer conectado</span>
|
|
</label>
|
|
<span
|
|
style={{
|
|
fontSize: '0.72rem',
|
|
color: isDark ? '#64748B' : '#94A3B8',
|
|
fontStyle: 'italic',
|
|
}}
|
|
>
|
|
(Guardar sesión)
|
|
</span>
|
|
</div>
|
|
|
|
{/* Mensaje de Error (si ocurre) */}
|
|
{errorMsg && (
|
|
<div
|
|
style={{
|
|
padding: '0.55rem 0.85rem',
|
|
backgroundColor: 'rgba(239, 68, 68, 0.12)',
|
|
border: '1px solid #EF4444',
|
|
borderRadius: '12px',
|
|
color: '#EF4444',
|
|
fontSize: '0.825rem',
|
|
fontWeight: 600,
|
|
textAlign: 'center',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: '0.4rem',
|
|
}}
|
|
>
|
|
<span>⚠️</span> {errorMsg}
|
|
</div>
|
|
)}
|
|
|
|
{/* Botón Ingresar / Login (Pill Shape estilo OnEver Desktop) */}
|
|
<button
|
|
type="submit"
|
|
disabled={isLoading}
|
|
style={{
|
|
width: '100%',
|
|
height: '46px',
|
|
borderRadius: '23px',
|
|
backgroundColor: isDark ? 'transparent' : '#2563EB',
|
|
color: isDark ? '#38BDF8' : '#FFFFFF',
|
|
border: isDark ? '2px solid #38BDF8' : '2px solid #2563EB',
|
|
fontSize: '0.95rem',
|
|
fontWeight: 700,
|
|
letterSpacing: '0.02em',
|
|
cursor: isLoading ? 'not-allowed' : 'pointer',
|
|
marginTop: '0.5rem',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: '0.5rem',
|
|
transition: 'all 0.2s ease',
|
|
boxShadow: isDark ? '0 4px 15px rgba(56, 189, 248, 0.15)' : '0 4px 15px rgba(37, 99, 235, 0.25)',
|
|
}}
|
|
onMouseEnter={(e) => {
|
|
if (!isLoading) {
|
|
e.currentTarget.style.backgroundColor = isDark ? '#38BDF8' : '#1D4ED8';
|
|
e.currentTarget.style.color = '#FFFFFF';
|
|
e.currentTarget.style.boxShadow = isDark
|
|
? '0 6px 20px rgba(56, 189, 248, 0.35)'
|
|
: '0 6px 20px rgba(37, 99, 235, 0.35)';
|
|
}
|
|
}}
|
|
onMouseLeave={(e) => {
|
|
if (!isLoading) {
|
|
e.currentTarget.style.backgroundColor = isDark ? 'transparent' : '#2563EB';
|
|
e.currentTarget.style.color = isDark ? '#38BDF8' : '#FFFFFF';
|
|
e.currentTarget.style.boxShadow = isDark
|
|
? '0 4px 15px rgba(56, 189, 248, 0.15)'
|
|
: '0 4px 15px rgba(37, 99, 235, 0.25)';
|
|
}
|
|
}}
|
|
>
|
|
{isLoading ? (
|
|
<>
|
|
<span>⏳</span> Validando credenciales...
|
|
</>
|
|
) : (
|
|
'Login'
|
|
)}
|
|
</button>
|
|
</form>
|
|
|
|
{/* Pie Informativo y Estado de Conexión */}
|
|
<div
|
|
style={{
|
|
marginTop: '1.75rem',
|
|
textAlign: 'center',
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
alignItems: 'center',
|
|
gap: '0.4rem',
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: '0.45rem',
|
|
fontSize: '0.75rem',
|
|
color: isDark ? '#94A3B8' : '#64748B',
|
|
fontWeight: 500,
|
|
}}
|
|
>
|
|
<img
|
|
src="/logo_os.png"
|
|
alt=""
|
|
style={{ width: '14px', height: '14px', objectFit: 'contain' }}
|
|
onError={(e) => {
|
|
(e.target as HTMLElement).style.display = 'none';
|
|
}}
|
|
/>
|
|
<span>OnEver Access · Control Web {APP_VERSION}</span>
|
|
<span
|
|
style={{
|
|
fontSize: '0.65rem',
|
|
padding: '0.1rem 0.35rem',
|
|
borderRadius: '4px',
|
|
backgroundColor: isDark ? '#1E293B' : '#E2E8F0',
|
|
color: isDark ? '#38BDF8' : '#0284C7',
|
|
fontWeight: 600,
|
|
}}
|
|
>
|
|
{APP_BUILD}
|
|
</span>
|
|
</div>
|
|
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.35rem',
|
|
fontSize: '0.725rem',
|
|
color: isDark ? '#64748B' : '#94A3B8',
|
|
}}
|
|
>
|
|
<span style={{ color: '#10B981', fontSize: '0.65rem' }}>●</span>
|
|
<span>Conectado a Microsoft SQL Server (Transaccional)</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|