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

Loading…
Cancel
Save