From 673d58023f4c0fe8633a107238ec8b577496717a Mon Sep 17 00:00:00 2001
From: Crunchy <3114200645@qq.com>
Date: 星期四, 07 十一月 2024 10:28:30 +0800
Subject: [PATCH] 添加登录验证码

---
 src/page/login/userlogin.vue |   49 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/src/page/login/userlogin.vue b/src/page/login/userlogin.vue
index 179116e..928a509 100644
--- a/src/page/login/userlogin.vue
+++ b/src/page/login/userlogin.vue
@@ -35,6 +35,25 @@
         <i slot="prefix" class="iconfont icon-mima"></i>
       </el-input>
     </el-form-item>
+    <el-form-item prop="loginCode">
+      <el-col :span="16">
+        <el-input
+          v-model="loginCode"
+          size="small"
+          auto-complete="off"
+          placeholder="璇疯緭鍏ラ獙璇佺爜"
+          @keyup.enter.native="handleLogin"
+        >
+        </el-input>
+      </el-col>
+      <el-col :span="6" :offset="2">
+        <login-code
+          :key="refreshKey"
+          :identifyCode="loginCodeValue"
+          @refresh="refreshLoginValueCode"
+        />
+      </el-col>
+    </el-form-item>
     <el-form-item>
       <el-button
         type="primary"
@@ -51,16 +70,14 @@
 </template>
 
 <script>
-import { randomLenNum } from '@/util/util'
 import { mapGetters } from 'vuex'
-import { getCode } from '@/api/code'
-import Verify from '@/components/verifition/Verify'
 import { getSsoAuthUrl } from '@/api/login'
+import LoginCode from '@/page/login/LoginCode.vue'
 
 export default {
   name: 'Userlogin',
   components: {
-    Verify
+    LoginCode
   },
   data() {
     return {
@@ -89,7 +106,12 @@
         ]
       },
       passwordType: 'password',
-      SSO: window.location.hash
+      SSO: window.location.hash,
+      loginCode: null,
+      loginCodeValue: Math.random()
+        .toString(36)
+        .substr(2, 4),
+      refreshKey: 0
     }
   },
   created() {
@@ -112,11 +134,21 @@
         : (this.passwordType = '')
     },
     handleLogin() {
+      if (!this.loginCode) {
+        this.$message.error('璇疯緭鍏ラ獙璇佺爜')
+        return
+      }
+      if (this.loginCode.toLowerCase() !== this.loginCodeValue) {
+        this.$message.error('楠岃瘉鐮佷笉姝g‘')
+        return
+      }
       this.$refs.loginForm.validate((valid) => {
         if (valid) {
           this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
             this.$router.push({ path: this.tagWel.value })
           })
+        } else {
+          this.refreshLoginValueCode()
         }
       })
     },
@@ -127,6 +159,13 @@
           this.$router.push({ path: this.tagWel.value })
         })
       }
+    },
+    // 鍒锋柊楠岃瘉鐮�
+    refreshLoginValueCode() {
+      this.loginCodeValue = Math.random()
+        .toString(36)
+        .substr(2, 4)
+      this.refreshKey++
     }
   }
 }

--
Gitblit v1.9.3