fix: login page not redirecting after successful login

- Replace validate(async callback) with await validate() Promise API
- Use window.location.replace('/') for cleaner redirect
- Unify form submission via @submit.prevent and native-type submit
- Remove duplicate click and keyup.enter handlers
feature/20260628/refactor-frontend-modernization
Lxy 2 weeks ago
parent 315f89eaba
commit 0417d5a945

@ -21,16 +21,15 @@
:prefix-icon="Lock"
size="large"
show-password
@keyup.enter="handleLogin"
/>
</el-form-item>
<el-form-item>
<el-button
type="primary"
native-type="submit"
size="large"
style="width: 100%"
:loading="loading"
@click="handleLogin"
>
登录
</el-button>
@ -66,21 +65,21 @@ const rules = {
const handleLogin = async () => {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (valid) {
loading.value = true
try {
// 使 Promise
await formRef.value.validate()
loading.value = true
await userStore.login(loginForm.username, loginForm.password)
ElMessage.success('登录成功')
router.push('/')
// 使 window.location.replace
window.location.replace('/')
} catch (error: any) {
console.error('Login error:', error)
ElMessage.error(error.message || '登录失败,请检查用户名和密码')
} finally {
loading.value = false
}
}
})
}
</script>
<style scoped lang="scss">

Loading…
Cancel
Save