import "./styles/login.css"; import { Template } from "interface/template"; import { Container, Heading, Text, Box, Flex, Button } from "@radix-ui/themes"; import { PersonIcon, LockClosedIcon } from "@radix-ui/react-icons"; import { useEffect, useRef, useState, useMemo } from "react"; import { gsap } from "gsap"; import { AnimatedBackground } from "hooks/Background"; import { useThemeMode, ThemeModeToggle } from "hooks/ThemeMode"; import { useNotification } from "hooks/Notification"; export default new Template({}, ({ http, args }) => { const containerRef = useRef(null); const [isVisible, setIsVisible] = useState(false); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const { mode } = useThemeMode(); const [hasBackgroundError, setHasBackgroundError] = useState(false); const notification = useNotification(); useEffect(() => { setIsVisible(true); const ctx = gsap.context(() => { // 登录框动画 gsap.from(".login-box", { y: 30, opacity: 0, duration: 1, ease: "power3.out", }); // 表单元素动画 gsap.from(".form-element", { x: -20, opacity: 0, duration: 0.8, stagger: 0.1, ease: "power2.out", delay: 0.3, }); // 按钮动画 gsap.from(".login-button", { scale: 0.9, opacity: 0, duration: 0.5, ease: "back.out(1.7)", delay: 0.8, }); }, containerRef); return () => ctx.revert(); }, []); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { // 这里添加登录逻辑 await new Promise((resolve) => setTimeout(resolve, 1500)); // 模拟API请求 // 登录成功的通知 notification.success("登录成功", "欢迎回来!"); // 登录成功后的处理 console.log("Login successful"); } catch (error) { // 登录失败的通知 notification.error("登录失败", "用户名或密码错误"); console.error("Login failed:", error); } finally { setIsLoading(false); } }; const handleBackgroundError = () => { console.log("Background failed to load, switching to fallback"); setHasBackgroundError(true); }; // 使用 useMemo 包裹背景组件 const backgroundComponent = useMemo( () => !hasBackgroundError && ( ), [hasBackgroundError], ); return (
{backgroundComponent} {/* Logo */} 后台 {/* 登录表单 */}
{/* 用户名输入框 */} setUsername(e.target.value)} required /> {/* 密码输入框 */} setPassword(e.target.value)} required /> {/* 登录按钮 */} {/* 其他选项 */} 忘记密码?
); });