241 lines
9.0 KiB
TypeScript
241 lines
9.0 KiB
TypeScript
"use client"
|
|
|
|
import type React from "react"
|
|
|
|
import { useState } from "react"
|
|
import Link from "next/link"
|
|
import { useRouter } from "next/navigation"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Input } from "@/components/ui/input"
|
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
|
|
import { Label } from "@/components/ui/label"
|
|
import { Checkbox } from "@/components/ui/checkbox"
|
|
import { Sparkles, Mail, Lock, Phone, User, ArrowRight, Loader2 } from "lucide-react"
|
|
|
|
export default function RegisterPage() {
|
|
const router = useRouter()
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
const [username, setUsername] = useState("")
|
|
const [email, setEmail] = useState("")
|
|
const [phone, setPhone] = useState("")
|
|
const [password, setPassword] = useState("")
|
|
const [confirmPassword, setConfirmPassword] = useState("")
|
|
const [verificationCode, setVerificationCode] = useState("")
|
|
const [isSendingCode, setIsSendingCode] = useState(false)
|
|
const [countdown, setCountdown] = useState(0)
|
|
|
|
const handleRegister = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
setIsLoading(true)
|
|
|
|
try {
|
|
// 模拟注册请求
|
|
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
|
|
// 注册成功后跳转到登录页
|
|
router.push("/login")
|
|
} catch (error) {
|
|
console.error("注册失败", error)
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
const handleSendVerificationCode = async () => {
|
|
if (!phone || phone.length !== 11 || isSendingCode) return
|
|
|
|
setIsSendingCode(true)
|
|
|
|
try {
|
|
// 模拟发送验证码请求
|
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
|
|
// 开始倒计时
|
|
setCountdown(60)
|
|
const timer = setInterval(() => {
|
|
setCountdown((prev) => {
|
|
if (prev <= 1) {
|
|
clearInterval(timer)
|
|
setIsSendingCode(false)
|
|
return 0
|
|
}
|
|
return prev - 1
|
|
})
|
|
}, 1000)
|
|
} catch (error) {
|
|
console.error("发送验证码失败", error)
|
|
setIsSendingCode(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen w-full flex items-center justify-center bg-gradient-to-br from-gray-50 to-white p-4">
|
|
<div className="absolute top-0 right-0 w-1/2 h-64 bg-gradient-to-bl from-pink-200 via-purple-200 to-transparent opacity-20 rounded-bl-full" />
|
|
<div className="absolute bottom-0 left-0 w-1/2 h-64 bg-gradient-to-tr from-blue-200 via-purple-200 to-transparent opacity-20 rounded-tr-full" />
|
|
|
|
<Card className="w-full max-w-md border-none shadow-xl bg-white/80 backdrop-blur-sm">
|
|
<CardHeader className="space-y-2 text-center">
|
|
<div className="flex justify-center mb-2">
|
|
<div className="h-12 w-12 rounded-full bg-gradient-to-br from-pink-500 to-purple-600 flex items-center justify-center">
|
|
<Sparkles className="h-6 w-6 text-white" />
|
|
</div>
|
|
</div>
|
|
<CardTitle className="text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-pink-600 to-purple-600">
|
|
创建新账户
|
|
</CardTitle>
|
|
<CardDescription>请填写以下信息完成注册</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={handleRegister} className="space-y-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="username">用户名</Label>
|
|
<div className="relative">
|
|
<User className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
id="username"
|
|
type="text"
|
|
placeholder="请输入用户名"
|
|
className="pl-10 border-gray-300 focus-visible:ring-pink-500"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="email">邮箱地址</Label>
|
|
<div className="relative">
|
|
<Mail className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
placeholder="请输入邮箱地址"
|
|
className="pl-10 border-gray-300 focus-visible:ring-pink-500"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="phone">手机号码</Label>
|
|
<div className="relative">
|
|
<Phone className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
id="phone"
|
|
type="tel"
|
|
placeholder="请输入手机号码"
|
|
className="pl-10 border-gray-300 focus-visible:ring-pink-500"
|
|
value={phone}
|
|
onChange={(e) => setPhone(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="verificationCode">验证码</Label>
|
|
<div className="flex space-x-2">
|
|
<div className="relative flex-1">
|
|
<Input
|
|
id="verificationCode"
|
|
type="text"
|
|
placeholder="请输入验证码"
|
|
className="border-gray-300 focus-visible:ring-pink-500"
|
|
value={verificationCode}
|
|
onChange={(e) => setVerificationCode(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
className="min-w-[120px] hover:bg-pink-50 hover:text-pink-700 transition-all duration-200"
|
|
onClick={handleSendVerificationCode}
|
|
disabled={isSendingCode || !phone || phone.length !== 11}
|
|
>
|
|
{countdown > 0 ? `${countdown}秒后重发` : "获取验证码"}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="password">密码</Label>
|
|
<div className="relative">
|
|
<Lock className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
placeholder="请输入密码"
|
|
className="pl-10 border-gray-300 focus-visible:ring-pink-500"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="confirmPassword">确认密码</Label>
|
|
<div className="relative">
|
|
<Lock className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
|
|
<Input
|
|
id="confirmPassword"
|
|
type="password"
|
|
placeholder="请再次输入密码"
|
|
className="pl-10 border-gray-300 focus-visible:ring-pink-500"
|
|
value={confirmPassword}
|
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-2">
|
|
<Checkbox id="terms" required />
|
|
<Label htmlFor="terms" className="text-sm font-normal cursor-pointer">
|
|
我已阅读并同意
|
|
<Link href="/terms" className="text-pink-600 hover:text-pink-700 hover:underline ml-1">
|
|
服务条款
|
|
</Link>
|
|
和
|
|
<Link href="/privacy" className="text-pink-600 hover:text-pink-700 hover:underline ml-1">
|
|
隐私政策
|
|
</Link>
|
|
</Label>
|
|
</div>
|
|
|
|
<Button
|
|
type="submit"
|
|
className="w-full bg-gradient-to-r from-pink-500 to-purple-600 hover:from-pink-600 hover:to-purple-700 transition-all duration-300 shadow-md hover:shadow-lg"
|
|
disabled={isLoading}
|
|
>
|
|
{isLoading ? (
|
|
<>
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
注册中...
|
|
</>
|
|
) : (
|
|
<>
|
|
注册
|
|
<ArrowRight className="ml-2 h-4 w-4" />
|
|
</>
|
|
)}
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
<CardFooter className="flex flex-col space-y-4 pt-0">
|
|
<div className="text-center text-sm text-gray-500">
|
|
已有账户?{" "}
|
|
<Link href="/login" className="text-pink-600 hover:text-pink-700 hover:underline">
|
|
返回登录
|
|
</Link>
|
|
</div>
|
|
</CardFooter>
|
|
</Card>
|
|
</div>
|
|
)
|
|
}
|