import React, { useState } from 'react'; import { Form, Input, Button, Card, Typography, message } from 'antd'; import { UserOutlined, LockOutlined } from '@ant-design/icons'; const { Title } = Typography; const Login = ({ onLogin }) => { const [loading, setLoading] = useState(false); const onFinish = async (values) => { setLoading(true); try { // 调用后端登录API const response = await fetch('http://localhost:3001/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username: values.username, password: values.password, }), }); const data = await response.json(); if (data.success) { // 保存登录状态和令牌 localStorage.setItem('isLoggedIn', 'true'); localStorage.setItem('loginTime', Date.now().toString()); localStorage.setItem('authToken', data.token); localStorage.setItem('userInfo', JSON.stringify(data.user)); message.success(data.message || '登录成功!'); onLogin(true); } else { message.error(data.message || '登录失败!'); } } catch (error) { console.error('登录错误:', error); message.error('网络错误,请稍后重试!'); } finally { setLoading(false); } }; return (
会议签到系统

管理员登录

} placeholder="用户名" /> } placeholder="密码" />

默认账号:admin / admin123

); }; export default Login;