fix: prevent duplicate login requests

- Add isSubmitting guard to prevent multiple concurrent login requests
- Set loading and submitting flags before validation to avoid race conditions
- This fixes the issue where multiple /login requests were fired simultaneously
feature/20260628/refactor-frontend-modernization
Lxy 2 weeks ago
parent 0417d5a945
commit 9fd2e737b0

@ -51,6 +51,7 @@ const router = useRouter()
const userStore = useUserStore()
const formRef = ref<FormInstance>()
const loading = ref(false)
const isSubmitting = ref(false)
const loginForm = reactive({
username: '',
@ -63,12 +64,13 @@ const rules = {
}
const handleLogin = async () => {
if (!formRef.value) return
if (!formRef.value || isSubmitting.value) return
isSubmitting.value = true
loading.value = true
try {
// 使 Promise
await formRef.value.validate()
loading.value = true
await userStore.login(loginForm.username, loginForm.password)
ElMessage.success('登录成功')
// 使 window.location.replace
@ -78,6 +80,7 @@ const handleLogin = async () => {
ElMessage.error(error.message || '登录失败,请检查用户名和密码')
} finally {
loading.value = false
isSubmitting.value = false
}
}
</script>

Loading…
Cancel
Save