import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import UploadInput from '../workspace/UploadInput'; import { useVideoUpload } from '../../hooks/video/useVideoUpload'; import { useAuth } from '../../hooks/auth/useAuth'; import { useNavigate } from 'react-router-dom'; const Hero = () => { const { t } = useTranslation(['common', 'home']); const navigate = useNavigate(); const { isAuthenticated } = useAuth(); const { handleUploadSuccess, handleDownloadSuccess } = useVideoUpload(); // 延迟装饰元素的加载,优化 LCP const [decorationsReady, setDecorationsReady] = useState(false); useEffect(() => { // 使用 requestAnimationFrame 在下一帧加载装饰元素 // 确保关键内容(标题、副标题、上传框)先渲染 requestAnimationFrame(() => { setDecorationsReady(true); }); }, []); // 验证用户是否已登录的处理函数 const handleAuthCheck = (action: () => Promise) => { if (!isAuthenticated) { navigate('/login', { state: { from: '/', message: t('login_required_for_upload') } }); return Promise.resolve(); } return action(); }; // 封装上传和下载成功的处理函数 const handleAuthenticatedUpload = ( uploadId: string, fileName: string, fileSize: number, fileType: string, duration?: number, filePath?: string, videoUrl?: string, projectId?: string ) => { return handleAuthCheck(() => handleUploadSuccess(uploadId, fileName, fileSize, fileType, duration, filePath, videoUrl, projectId)); }; const handleAuthenticatedDownload = ( downloadId: string, fileName: string, fileType: string, filePath: string, videoUrl?: string, projectId?: string ) => { return handleAuthCheck(() => handleDownloadSuccess(downloadId, fileName, fileType, filePath, videoUrl, projectId)); }; return (
{/* 简化的装饰性背景元素 - 减少数量和尺寸,延迟加载 */} {decorationsReady && (
{/* 减少到 2 个装饰元素,尺寸从 600px 减小到 400px */}
)} {/* 微妙的网格背景 - 延迟加载 */} {decorationsReady && (
)} {/* 关键内容:立即渲染,无条件显示,优化 LCP */}
{/* 主标题 - 渐变动画立即启用 */}

{t('welcome')}

{/* 副标题 */}

{t('hero_desc')}

{/* 上传输入框 - 简化装饰效果 */}
{/* 光晕效果 - 仅在装饰元素加载后显示 */} {decorationsReady && (
)}
{/* 信任指标 */}
{t('hero_trust_served')} 50,000+ {t('hero_trust_creators')}
{t('hero_trust_processed')} 1M+ {t('hero_trust_videos')}
{/* 渐变动画样式 - 使用 will-change 优化性能 */}