"use client" import { useState, useEffect } from "react" import { toast } from "sonner" import { Spinner } from "@/components/ui/spinner" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { motion, useAnimation } from "motion/react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion" import { SquareArrowUpRight } from 'lucide-react'; import { cn } from "@/lib/utils" import services from "@/lib/services" import { termsSections } from "@/components/common/docs/terms" import { privacySections } from "@/components/common/docs/privacy" /** * 登录表单组件 * 显示登录表单和登录按钮 * * @example * ```tsx * * ``` * @param {React.ComponentProps<"div">} props - 组件属性 * @param {string} className - 组件类名 * @returns {React.ReactNode} 登录表单组件 */ export function LoginForm({ className, ...props }: React.ComponentProps<"div">) { const [isLoading, setIsLoading] = useState(false) const [hasAgreed, setHasAgreed] = useState(false) const controls = useAnimation() useEffect(() => { const agreed = localStorage.getItem("loginPromptAgreed") === "true" if (agreed) { setHasAgreed(true) } }, []) const handleAgreementChange = (checked: boolean | string) => { const isChecked = checked === true setHasAgreed(isChecked) if (isChecked) { localStorage.setItem("loginPromptAgreed", "true") } else { localStorage.removeItem("loginPromptAgreed") } } /* 处理登录 */ const handleLogin = async () => { if (!hasAgreed) { toast.error("请先阅读并勾选服务条款和隐私政策") controls.start({ x: [0, -4, 4, -4, 4, 0], color: ["#ef4444", "inherit"], transition: { duration: 0.5 } }) return } setIsLoading(true) try { await services.auth.initiateLogin() } catch (error) { setIsLoading(false) console.error('Login error:', error) const message = error instanceof Error ? error.message : "登录失败,请重试" toast.error(message, { duration: 5000, description: error instanceof Error && error.name === 'NetworkError' ? '请确认后端服务已启动' : undefined }) } } return (
) }