Optimize login

This commit is contained in:
2023-10-10 17:05:30 +08:00
parent 81c490853a
commit a10b418ae9
2 changed files with 42 additions and 38 deletions

View File

@@ -16,43 +16,47 @@ const Login: React.FC = () => {
const onFinish = (values: LoginForm) => { const onFinish = (values: LoginForm) => {
setIsLoggingIn(true) setIsLoggingIn(true)
void login(values.username, values.password).then((value) => { void login(values.username, values.password)
const res = value.data .then((value) => {
const { code, data } = res const res = value.data
switch (code) { const { code, data } = res
case SYSTEM_LOGIN_SUCCESS: switch (code) {
setToken(data?.token ?? '') case SYSTEM_LOGIN_SUCCESS:
void messageApi.success('登录成功') setToken(data?.token ?? '')
setTimeout(() => { void messageApi.success('登录成功')
navigate('/') setTimeout(() => {
}, 1500) navigate('/')
break }, 1500)
case SYSTEM_USERNAME_NOT_FOUND: break
case SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR: case SYSTEM_USERNAME_NOT_FOUND:
void messageApi.error( case SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR:
<> void messageApi.error(
<strong></strong><strong></strong> <>
</> <strong></strong><strong></strong>
) </>
setIsLoggingIn(false) )
break setIsLoggingIn(false)
case SYSTEM_USER_DISABLE: break
void messageApi.error( case SYSTEM_USER_DISABLE:
<> void messageApi.error(
<strong></strong> <>
</> <strong></strong>
) </>
setIsLoggingIn(false) )
break setIsLoggingIn(false)
default: break
void messageApi.error( default:
<> void messageApi.error(
<strong></strong> <>
</> <strong></strong>
) </>
setIsLoggingIn(false) )
} setIsLoggingIn(false)
}) }
})
.catch(() => {
setIsLoggingIn(false)
})
} }
return ( return (

View File

@@ -12,7 +12,7 @@ import { message } from 'antd'
const service: AxiosInstance = axios.create({ const service: AxiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_URL, baseURL: import.meta.env.VITE_API_URL,
timeout: 10000, timeout: 30000,
withCredentials: false withCredentials: false
}) })