test/frontend/src/pages/Login.tsx
2025-11-21 16:33:06 +08:00

41 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Card, Form, Input, Button, message } from 'antd';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
const LoginPage = () => {
const { login } = useAuth();
const navigate = useNavigate();
const onFinish = async (values: any) => {
try {
await login(values.username, values.password);
message.success('登录成功');
navigate('/admin/products');
} catch (error: any) {
message.error(error?.response?.data?.message || '登录失败');
}
};
return (
<Card title="商家后台登录" style={{ maxWidth: 420, margin: '0 auto' }}>
<Form layout="vertical" onFinish={onFinish} initialValues={{ username: 'demo', password: 'demo123' }}>
<Form.Item name="username" label="账号" rules={[{ required: true }]}
extra="演示账号demo / demo123">
<Input placeholder="请输入账号" />
</Form.Item>
<Form.Item name="password" label="密码" rules={[{ required: true }]}>
<Input.Password placeholder="请输入密码" />
</Form.Item>
<Button type="primary" htmlType="submit" block>
</Button>
<Button type="link" block onClick={() => navigate('/register')}>
</Button>
</Form>
</Card>
);
};
export default LoginPage;