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) => {
setIsLoggingIn(true)
void login(values.username, values.password).then((value) => {
const res = value.data
const { code, data } = res
switch (code) {
case SYSTEM_LOGIN_SUCCESS:
setToken(data?.token ?? '')
void messageApi.success('登录成功')
setTimeout(() => {
navigate('/')
}, 1500)
break
case SYSTEM_USERNAME_NOT_FOUND:
case SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR:
void messageApi.error(
<>
<strong></strong><strong></strong>
</>
)
setIsLoggingIn(false)
break
case SYSTEM_USER_DISABLE:
void messageApi.error(
<>
<strong></strong>
</>
)
setIsLoggingIn(false)
break
default:
void messageApi.error(
<>
<strong></strong>
</>
)
setIsLoggingIn(false)
}
})
void login(values.username, values.password)
.then((value) => {
const res = value.data
const { code, data } = res
switch (code) {
case SYSTEM_LOGIN_SUCCESS:
setToken(data?.token ?? '')
void messageApi.success('登录成功')
setTimeout(() => {
navigate('/')
}, 1500)
break
case SYSTEM_USERNAME_NOT_FOUND:
case SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR:
void messageApi.error(
<>
<strong></strong><strong></strong>
</>
)
setIsLoggingIn(false)
break
case SYSTEM_USER_DISABLE:
void messageApi.error(
<>
<strong></strong>
</>
)
setIsLoggingIn(false)
break
default:
void messageApi.error(
<>
<strong></strong>
</>
)
setIsLoggingIn(false)
}
})
.catch(() => {
setIsLoggingIn(false)
})
}
return (

View File

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