74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { Button, Checkbox, Form, Input, Layout, message } from 'antd';
|
|
import { LockOutlined, UserOutlined } from '@ant-design/icons';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { authService } from '../services/auth.service';
|
|
|
|
const { Content } = Layout;
|
|
|
|
const LoginPage: React.FC = () => {
|
|
const [loading, setLoading] = useState(false);
|
|
const navigate = useNavigate();
|
|
|
|
const onFinish = async (values: any) => {
|
|
setLoading(true);
|
|
try {
|
|
console.log('Login attempt with:', values);
|
|
const response = await authService.login(values.username, values.password);
|
|
console.log('Login response:', response);
|
|
message.success('登录成功');
|
|
navigate('/');
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
message.error('登录失败,请检查用户名和密码');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Layout className="min-h-screen bg-gray-100">
|
|
<Content className="flex items-center justify-center p-4">
|
|
<div className="bg-white rounded-lg shadow-lg p-8 w-full max-w-md">
|
|
<h1 className="text-2xl font-bold text-center mb-6">ERP系统登录</h1>
|
|
<Form
|
|
name="login"
|
|
initialValues={{ remember: true }}
|
|
onFinish={onFinish}
|
|
>
|
|
<Form.Item
|
|
name="username"
|
|
rules={[{ required: true, message: '请输入用户名' }]}
|
|
>
|
|
<Input prefix={<UserOutlined />} placeholder="用户名" />
|
|
</Form.Item>
|
|
<Form.Item
|
|
name="password"
|
|
rules={[{ required: true, message: '请输入密码' }]}
|
|
>
|
|
<Input.Password prefix={<LockOutlined />} placeholder="密码" />
|
|
</Form.Item>
|
|
<Form.Item>
|
|
<Form.Item name="remember" valuePropName="checked" noStyle>
|
|
<Checkbox>记住我</Checkbox>
|
|
</Form.Item>
|
|
</Form.Item>
|
|
<Form.Item>
|
|
<Button
|
|
type="primary"
|
|
htmlType="submit"
|
|
className="w-full"
|
|
loading={loading}
|
|
>
|
|
登录
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
</div>
|
|
</Content>
|
|
</Layout>
|
|
);
|
|
};
|
|
|
|
export default LoginPage;
|