|
|
|
@ -44,7 +44,7 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import { onMounted, reactive, ref, toRefs, watch } from 'vue' |
|
|
|
|
import { onMounted, reactive, ref, toRefs, watch,onBeforeUnmount } from 'vue' |
|
|
|
|
import { getCode } from '@/api/user' |
|
|
|
|
import userStore from '@/store/module/user' |
|
|
|
|
import { ElMessage } from 'element-plus' |
|
|
|
@ -83,10 +83,8 @@ const submit = async () => { |
|
|
|
|
try { |
|
|
|
|
const res = await useUserStore.login(data) |
|
|
|
|
console.log(res) |
|
|
|
|
if (res === 0) { |
|
|
|
|
ElMessage('验证码错误') |
|
|
|
|
getcodeinfo() |
|
|
|
|
} else if (res === 1) { |
|
|
|
|
isSubmitting.value = false |
|
|
|
|
if (res === 1) { |
|
|
|
|
ElMessage('账号或密码错误') |
|
|
|
|
getcodeinfo() |
|
|
|
|
} else { |
|
|
|
@ -94,6 +92,8 @@ const submit = async () => { |
|
|
|
|
} |
|
|
|
|
} catch (error: any) { |
|
|
|
|
ElMessage(error.data.message) |
|
|
|
|
getcodeinfo() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
onMounted(() => { |
|
|
|
@ -105,11 +105,18 @@ onMounted(() => { |
|
|
|
|
registered() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
onBeforeUnmount(() => { |
|
|
|
|
window.removeEventListener('keyup', keyDown) // 清理事件监听器 |
|
|
|
|
}) |
|
|
|
|
const isSubmitting = ref(false) // 添加一个变量来判断是否正在提交 |
|
|
|
|
const keyDown = (e: any) => { |
|
|
|
|
//如果是回车则执行登录方法 |
|
|
|
|
// 如果已经在提交中,直接返回 |
|
|
|
|
if (isSubmitting.value) return |
|
|
|
|
|
|
|
|
|
// 如果按下的是回车键 |
|
|
|
|
if (e.keyCode == 13) { |
|
|
|
|
//需要执行的登录方法 |
|
|
|
|
submit() |
|
|
|
|
isSubmitting.value = true // 设置为正在提交状态 |
|
|
|
|
submit() // 执行提交操作 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|