@ -51,6 +51,7 @@ const router = useRouter()
const userStore = useUserStore ( )
const userStore = useUserStore ( )
const formRef = ref < FormInstance > ( )
const formRef = ref < FormInstance > ( )
const loading = ref ( false )
const loading = ref ( false )
const isSubmitting = ref ( false )
const loginForm = reactive ( {
const loginForm = reactive ( {
username : '' ,
username : '' ,
@ -63,12 +64,13 @@ const rules = {
}
}
const handleLogin = async ( ) => {
const handleLogin = async ( ) => {
if ( ! formRef . value ) return
if ( ! formRef . value || isSubmitting . value ) return
isSubmitting . value = true
loading . value = true
try {
try {
/ / 使 用 P r o m i s e 方 式 等 待 校 验 完 成
/ / 使 用 P r o m i s e 方 式 等 待 校 验 完 成
await formRef . value . validate ( )
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 ( '登录成功' )
/ / 使 用 w i n d o w . l o c a t i o n . r e p l a c e 确 保 页 面 完 全 刷 新 并 跳 转 到 首 页
/ / 使 用 w i n d o w . l o c a t i o n . r e p l a c e 确 保 页 面 完 全 刷 新 并 跳 转 到 首 页
@ -78,6 +80,7 @@ const handleLogin = async () => {
ElMessage . error ( error . message || '登录失败,请检查用户名和密码' )
ElMessage . error ( error . message || '登录失败,请检查用户名和密码' )
} finally {
} finally {
loading . value = false
loading . value = false
isSubmitting . value = false
}
}
}
}
< / script >
< / script >