Optimize login
This commit is contained in:
@@ -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 (
|
||||||
|
|||||||
@@ -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
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user