feat: 登录时要选择中英文,方便业务数据查询。

perf/export-docx
Jimmy Liow 11 months ago
parent 4688c78dbd
commit 872f302ed4

@ -5,7 +5,6 @@ import { DownOutlined } from '@ant-design/icons';
import 'antd/dist/reset.css'; import 'antd/dist/reset.css';
import AppLogo from '@/assets/logo-gh.png'; import AppLogo from '@/assets/logo-gh.png';
import { isEmpty } from '@/utils/commons'; import { isEmpty } from '@/utils/commons';
import Language from '../i18n/LanguageSwitcher';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import zhLocale from 'antd/locale/zh_CN'; import zhLocale from 'antd/locale/zh_CN';
import enLocale from 'antd/locale/en_US'; import enLocale from 'antd/locale/en_US';
@ -158,9 +157,6 @@ function App() {
</a> </a>
</Dropdown> </Dropdown>
</Col> </Col>
<Col span={2}>
<Language />
</Col>
</Row> </Row>
</Header> </Header>
<Content className='p-6 m-0 min-h-72 bg-white'> <Content className='p-6 m-0 min-h-72 bg-white'>

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

@ -28,9 +28,6 @@ function Standlone() {
<img src={AppLogo} className='float-left h-9 my-4 mr-6 ml-0 bg-white/30' alt='App logo' /> <img src={AppLogo} className='float-left h-9 my-4 mr-6 ml-0 bg-white/30' alt='App logo' />
</Col> </Col>
<Col span={5}><h1 className='text-white text-center'>Global Highlights Hub</h1></Col> <Col span={5}><h1 className='text-white text-center'>Global Highlights Hub</h1></Col>
<Col span={2}>
<Language />
</Col>
</Row> </Row>
</Header> </Header>
<Content className='p-6 m-0 min-h-72 bg-white'> <Content className='p-6 m-0 min-h-72 bg-white'>

Loading…
Cancel
Save