import React, { useState } from 'react'; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { toast } from 'sonner'; import { request } from '@/utils/request'; import { useIsMobile } from '@/hooks/use-mobile'; import ClickTextCapt from "@/components/goCaptcha/ClickTextCapt.jsx"; interface PhoneLoginProps { onLogin: (phone: string, code: string) => void; } const PhoneLogin: React.FC = ({ handleLoginSuccess }) => { const [phone, setPhone] = useState(''); const [code, setCode] = useState(''); const [countdown, setCountdown] = useState(0); const [isLoading, setIsLoading] = useState(false); const [showCaptcha, setShowCaptcha] = useState(false); // 新增弹窗状态 const isMobile = useIsMobile(); // 获取备案号配置 const icpNumber = (window as any).APP_CONFIG?.ICP_NUMBER; // 发送验证码成功后倒计时 const handleSendCodeSuccess = () => { // 开始倒计时 setCountdown(60); const timer = setInterval(() => { setCountdown((prev) => { if (prev <= 1) { clearInterval(timer); return 0; } return prev - 1; }); }, 1000); } // 点击发送验证码按钮 const handleSendCode = async () => { if (!phone || !/^1[3-9]\d{9}$/.test(phone)) { toast.error('请输入正确的手机号'); return; } setShowCaptcha(true); // 弹出图形验证码弹窗 }; // 图形验证码通过后的回调 // const handleCaptchaSuccess = async () => { // setShowCaptcha(false); // await realSendCode(); // }; // 提交登录 const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!phone || !code) { toast.error('请输入手机号和验证码'); return; } setIsLoading(true); try { const response = await request(`/api/login`, { method: 'POST', body: JSON.stringify({ phone, code }), }); const data = await response.json(); //执行登录成功回调 handleLoginSuccess(data.data.token); } catch (error) { console.error('登录失败:', error); toast.error(error instanceof Error ? error.message : '登录失败,请重试'); } finally { setIsLoading(false); } }; return (
{/* Logo */}
botgroup.chat
仅支持中国大陆手机号登录
+86 setPhone(e.target.value)} maxLength={11} className={`border-none focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 shadow-none p-0 ${isMobile ? 'text-sm' : 'text-base'}`} />
setCode(e.target.value)} maxLength={6} className={`border rounded-lg ${isMobile ? 'p-2.5' : 'p-3'} ${isMobile ? 'h-[42px]' : 'h-[46px]'} focus:border-[#ff6600] focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 shadow-none ${isMobile ? 'text-sm' : 'text-base'}`} />
{/* 弹窗形式的图形验证码 */} {showCaptcha && (
)} {/* 备案号显示 */} {icpNumber && (
{icpNumber}
)}
); }; export default PhoneLogin;