|
|
|
@ -1,18 +1,21 @@
|
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
|
import { Button, Form, Input, Row, App } from 'antd'
|
|
|
|
|
import { Button, Form, Input, Row, Radio, App } from 'antd'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import useAuthStore from '@/stores/Auth'
|
|
|
|
|
import { appendRequestParams } from '@/utils/request'
|
|
|
|
|
|
|
|
|
|
function Login() {
|
|
|
|
|
const [authenticate, loginStatus, defaultRoute] =
|
|
|
|
|
useAuthStore((state) => [state.authenticate, state.loginStatus, state.defaultRoute])
|
|
|
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const { t, i18n } = useTranslation()
|
|
|
|
|
const { notification } = App.useApp()
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const [form] = Form.useForm()
|
|
|
|
|
|
|
|
|
|
const defaultLng = localStorage.getItem('i18nextLng')??'zh'
|
|
|
|
|
|
|
|
|
|
useEffect (() => {
|
|
|
|
|
if (loginStatus === 302) {
|
|
|
|
|
navigate(defaultRoute)
|
|
|
|
@ -36,6 +39,11 @@ function Login() {
|
|
|
|
|
console.log('Failed:', errorInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleLngChange = (e) => {
|
|
|
|
|
appendRequestParams('lgc', e.target.value === 'zh' ? 2 : 1)
|
|
|
|
|
i18n.changeLanguage(e.target.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Row justify='center' align='middle' className='min-h-96'>
|
|
|
|
|
<Form
|
|
|
|
@ -51,7 +59,7 @@ function Login() {
|
|
|
|
|
}}
|
|
|
|
|
className='max-w-xl'
|
|
|
|
|
initialValues={{
|
|
|
|
|
remember: true,
|
|
|
|
|
language: defaultLng,
|
|
|
|
|
}}
|
|
|
|
|
onFinish={onFinish}
|
|
|
|
|
onFinishFailed={onFinishFailed}
|
|
|
|
@ -81,8 +89,13 @@ function Login() {
|
|
|
|
|
>
|
|
|
|
|
<Input.Password />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
>
|
|
|
|
|
<Form.Item name='language'>
|
|
|
|
|
<Radio.Group onChange={handleLngChange}>
|
|
|
|
|
<Radio value='zh'>中文</Radio>
|
|
|
|
|
<Radio value='en'>English</Radio>
|
|
|
|
|
</Radio.Group>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item>
|
|
|
|
|
<Button type='primary' htmlType='submit' className='w-full'>
|
|
|
|
|
{t('Login')}
|
|
|
|
|
</Button>
|
|
|
|
|