刘恒 1 год назад
Родитель
Сommit
e08839ec77
1 измененных файлов с 17 добавлено и 3 удалено
  1. 17 3
      src/components/LoginForm/index.vue

+ 17 - 3
src/components/LoginForm/index.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
 import type { FormInstance, FormRules } from 'element-plus'
 import useUserStore from '@/store/modules/user'
-import { ref, useTemplateRef, onMounted } from 'vue'
+import { ref, useTemplateRef, onMounted,onUnmounted } from 'vue'
 
 defineOptions({
   name: 'LoginForm',
@@ -51,7 +51,11 @@ const rules = ref<FormRules>({
   ],
 })
 onMounted(() => {
-  refreshCaptcha()
+  refreshCaptcha();
+  window.addEventListener('keydown', handleEnter)
+});
+onUnmounted(() => {
+  window.removeEventListener('keydown', handleEnter, false)
 })
 //获取验证码接口
 function refreshCaptcha() {
@@ -64,6 +68,14 @@ function refreshCaptcha() {
     randnum;
   form.value.captchaId = randnum;
 }
+function handleEnter (e:any) {
+  // console.log(e)
+  // console.log(e)
+  if (e.keyCode == 13 || e.keyCode == 108) {
+    //登录接口逻辑
+    handleLogin()
+  }
+}
 function handleLogin() {
   formRef.value?.validate((valid) => {
     if (valid) {
@@ -184,7 +196,9 @@ function handleLogin() {
           忘记密码
         </ElLink>
       </div>
-      <ElButton class="loginCSS" :loading="loading" type="primary"  style="width: 100%;" @click.prevent="handleLogin">
+      <ElButton class="loginCSS" :loading="loading" type="primary" 
+      @keydown.enter="handleEnter"
+      style="width: 100%;" @click.prevent="handleLogin">
         登录
       </ElButton>
       <!-- <div class="mt-4 flex-center gap-2 text-sm color-[var(--el-text-color-secondary)]">