Skip to content

Commit

Permalink
完善登录页提示
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterH0323 committed Sep 7, 2024
1 parent 4832bae commit b2cf376
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions frontend/src/views/login/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ElMessage, ElNotification, type FormInstance, type FormRules } from 'el
import { loginRequest } from '@/api/user'
import { useTokenStore, type TokenItem } from '@/stores/userToken'
import { AxiosError } from 'axios'
const router = useRouter()
const route = useRoute()
Expand Down Expand Up @@ -67,14 +68,28 @@ const onSubmit = async () => {
isLogining.value = false
throw new Error('账号名或密码错误') // 抛出异常
}
// 弹窗提示
ElNotification({
title: '登录成功',
message: '欢迎',
type: 'success'
})
return res.data
})
.catch((error) => {
console.error(error)
isLogining.value = false
if (error.response && error.response.status === 401) {
ElMessage.error('账号名或密码错误')
isLogining.value = false
throw new Error('账号名或密码错误') // 抛出异常
} else if (error instanceof AxiosError) {
ElMessage.error('登录失败:' + error.message)
throw new Error('登录失败:' + error.message) // 抛出异常
} else {
ElMessage.error('未知错误:' + error)
throw new Error('未知错误:' + error) // 抛出异常
}
})
Expand All @@ -86,13 +101,6 @@ const onSubmit = async () => {
// 设置已经完成登录
isLogining.value = false
// 弹窗提示
ElNotification({
title: '登录成功',
message: '欢迎',
type: 'success'
})
router.push((route.query.redirect as string) || '/') // 页面跳转,如果是被未登录拦截的话,登录成功后跳转会目标页面
}
</script>
Expand Down

0 comments on commit b2cf376

Please sign in to comment.