import React, { useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { Sparkles, ArrowRight, Lock, User, Mail, ShieldCheck } from 'lucide-react'; export const LoginView = () => { const { login, register } = useAuth(); const [isLoginTab, setIsLoginTab] = useState(true); const [identifier, setIdentifier] = useState(''); const [password, setPassword] = useState(''); const [username, setUsername] = useState(''); const [loading, setLoading] = useState(false); const [errorMsg, setErrorMsg] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setErrorMsg(''); setLoading(true); try { if (isLoginTab) { const res = await login(identifier, password); if (!res.success) { setErrorMsg(res.message || '登录失败,请检查账号与密码'); } } else { if (!username.trim()) { setErrorMsg('请输入用户名'); setLoading(false); return; } const res = await register(username, identifier, password); if (!res.success) { setErrorMsg(res.message || '注册失败,请稍后重试'); } } } catch (err) { setErrorMsg('网络请求异常,请稍后重试'); } finally { setLoading(false); } }; return (
云端现场记录极简同步平台