import React, { useState } from 'react' import { useNavigate } from 'react-router-dom' import { Card, Form, Input, Button, Typography, Space, Alert, Flex, Divider } from 'antd' import { UserOutlined, LockOutlined, DashboardOutlined, DollarOutlined, ProjectOutlined, TeamOutlined } from '@ant-design/icons' import { useAuthStore } from '../../store/authStore' import { useLanguageStore } from '../../store/languageStore' import LanguageSelector from '../../components/common/LanguageSelector' const { Title, Text } = Typography const LoginPage: React.FC = () => { const navigate = useNavigate() const [form] = Form.useForm() const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const { login } = useAuthStore() const { t } = useLanguageStore() const handleSubmit = async (values: { username: string; password: string }) => { setLoading(true) setError(null) try { await login(values.username, values.password) navigate('/dashboard') } catch (err) { setError(err instanceof Error ? err.message : t('login.loginFailed')) } finally { setLoading(false) } } // 测试账户 const testAccounts = [ { username: 'admin', password: 'X123c321@', role: t('user.admin') }, { username: 'finance', password: 'X123c321@', role: t('user.finance') }, { username: 'manager', password: 'X123c321@', role: t('user.manager') }, { username: 'employee', password: 'X123c321@', role: t('user.employee') } ] const handleTestLogin = (username: string, password: string) => { form.setFieldsValue({ username, password }) form.submit() } return (
{/* 标题 */}
<DashboardOutlined style={{ marginRight: 12, color: '#1890ff' }} /> {t('login.title')} {t('login.subtitle')}
{/* 语言选择器 V2.0 */}
🌍 选择语言 / Select Language
{/* 错误提示 */} {error && ( setError(null)} /> )} {/* 登录表单 */}
} placeholder={t('login.usernamePlaceholder')} size="large" /> } placeholder={t('login.passwordPlaceholder')} size="large" />
{t('login.testAccounts')} {/* 测试账户 */} {testAccounts.map((account, index) => ( handleTestLogin(account.username, account.password)} style={{ cursor: 'pointer' }} > {account.role === t('user.admin') && } {account.role === t('user.finance') && } {account.role === t('user.manager') && } {account.role === t('user.employee') && } {account.role} {t('login.username')}: {account.username} / {t('login.password')}: {account.password} ))} {/* 功能说明 */} {t('menu.dashboard')}: • {t('features.projectManage')} • {t('features.advanceManage')} • {t('features.reimburseManage')} • {t('features.financeReport')} • {t('features.mobileSupport')} {/* 技术支持 */}
{t('login.techSupport')}
) } export default LoginPage