import React, { useState } from 'react'; import { useSecurity } from '../contexts/SecurityContext'; import { api } from '../services/api'; import { Lock, Loader2, Eye, EyeOff } from 'lucide-react'; interface Props { children: React.ReactNode; enabled?: boolean; // Whether protection is enabled for this user role } export const SensitiveContentProtection: React.FC = ({ children, enabled = true }) => { const { isSensitiveUnlocked, unlockSensitiveContent } = useSecurity(); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [showPassword, setShowPassword] = useState(false); // If protection is disabled (e.g. for Students/Admins if configured), just show content if (!enabled || isSensitiveUnlocked) { return <>{children}; } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!password) return; setLoading(true); setError(''); try { const isValid = await api.auth.verifyPassword(password); if (isValid) { unlockSensitiveContent(); } else { setError('密码错误,请重试'); } } catch (err) { setError('验证失败,请稍后重试'); } finally { setLoading(false); } }; return (
{/* Blurred Content Background */} {/* We render children to create the visual "content behind blur" effect. Pointer events are disabled to prevent interaction. A heavy blur and opacity layer is applied. */} {/* Overlay */}

敏感内容保护

为了保护学生隐私与数据安全
查看 成绩管理报表统计 需验证身份

setPassword(e.target.value)} className="w-full px-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none transition-all bg-gray-50 focus:bg-white text-gray-800" placeholder="请输入当前账号密码" autoFocus />
{error && (
{error}
)}
); };