|
|
|
@@ -3,8 +3,8 @@ import { getCaptchaImg, login } from '@/services/system/auth'; |
|
|
|
import { loginPasswordKey, loginUserKey, rememberPasswordKey } from '@/utils/localStorage'; |
|
|
|
import { to } from '@/utils/promise'; |
|
|
|
import { history, useModel } from '@umijs/max'; |
|
|
|
import { Button, Checkbox, Flex, Form, Image, Input, message } from 'antd'; |
|
|
|
import React, { useEffect, useState } from 'react'; |
|
|
|
import { Button, Checkbox, Flex, Form, Image, Input, message, type InputRef } from 'antd'; |
|
|
|
import { useEffect, useRef, useState } from 'react'; |
|
|
|
import { flushSync } from 'react-dom'; |
|
|
|
import styles from './login.less'; |
|
|
|
|
|
|
|
@@ -17,12 +17,13 @@ const LoginInputPrefix = ({ icon }: { icon: string }) => { |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
const Login: React.FC = () => { |
|
|
|
const Login = () => { |
|
|
|
const { initialState, setInitialState } = useModel('@@initialState'); |
|
|
|
const [captchaCode, setCaptchaCode] = useState<string>(''); |
|
|
|
const [uuid, setUuid] = useState<string>(''); |
|
|
|
const [form] = Form.useForm(); |
|
|
|
const [usernameReadOnly, setUsernameReadOnly] = useState<boolean>(true); |
|
|
|
const captchaInputRef = useRef<InputRef>(null); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
getCaptchaCode(); |
|
|
|
@@ -59,11 +60,11 @@ const Login: React.FC = () => { |
|
|
|
|
|
|
|
// 登录 |
|
|
|
const handleSubmit = async (values: API.LoginParams) => { |
|
|
|
const [response] = await to(login({ ...values, uuid })); |
|
|
|
if (response && response.data) { |
|
|
|
const [res, error] = await to(login({ ...values, uuid })); |
|
|
|
if (res && res.data) { |
|
|
|
const current = new Date(); |
|
|
|
const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60); |
|
|
|
const { access_token } = response.data; |
|
|
|
const { access_token } = res.data; |
|
|
|
setSessionToken(access_token, access_token, expireTime); |
|
|
|
message.success('登录成功!'); |
|
|
|
|
|
|
|
@@ -80,6 +81,10 @@ const Login: React.FC = () => { |
|
|
|
const urlParams = new URL(window.location.href).searchParams; |
|
|
|
history.push(urlParams.get('redirect') || '/'); |
|
|
|
} else { |
|
|
|
if (error?.data?.code === 500 && error?.data?.msg === '验证码错误') { |
|
|
|
captchaInputRef.current?.focus(); |
|
|
|
} |
|
|
|
|
|
|
|
clearSessionToken(); |
|
|
|
getCaptchaCode(); |
|
|
|
} |
|
|
|
@@ -156,6 +161,7 @@ const Login: React.FC = () => { |
|
|
|
prefix={ |
|
|
|
<LoginInputPrefix icon={require('@/assets/img/login-captcha.png')} /> |
|
|
|
} |
|
|
|
ref={captchaInputRef} |
|
|
|
allowClear |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
|