huangsijun
2025-11-06 25a3e9bb63fe83f7c82180a7d373a331b2f41acb
saas_vue/src/views/Login.vue
@@ -20,7 +20,7 @@
          </el-input>
        </div>
      </el-form-item>
      <el-form-item prop="verifycode" style="line-height:0px;">
      <el-form-item prop="verifycode" style="line-height:0px;" v-if="login_err_num >= 3">
        <div class="d-b-c">
          <div class="left-img-input" style="width: auto;">
            <el-input v-model="ruleForm2.verifycode" ref="verifycode" placeholder="验证码" class="l-input"
@@ -48,6 +48,7 @@
  import UserApi from '@/api/user.js';
  import {
    setCookie,
    getCookie,
    setSessionStorage
  } from '@/utils/base.js';
  export default {
@@ -57,16 +58,18 @@
    data() {
      // 验证码自定义验证规则
      const validateVerifycode = (rule, value, callback) => {
        if (value === "") {
          this.refreshCode();
          callback(new Error('请输入验证码'))
        } else if (value !== this.identifyCode) {
          console.log('验证码:', value);
          this.refreshCode();
          callback(new Error('验证码不正确!'))
        } else {
          callback()
        // 密码输错3次以上才出现验证码 by lyzflash
        if (this.login_err_num >= 3) {
          if (value === "") {
            this.refreshCode();
            callback(new Error('请输入验证码'))
          } else if (value !== this.identifyCode) {
            console.log('验证码:', value);
            this.refreshCode();
            callback(new Error('验证码不正确!'))
          }
        }
        callback();
      }
      return {
        loginForm: {},
@@ -94,11 +97,13 @@
            validator: validateVerifycode
          }]
        },
        checked: true
        checked: true,
        login_err_num: 0, // 登录错误次数
      };
    },
    created() {
      this.refreshCode();
      this.login_err_num = parseInt(getCookie('login_err_num') || 0);
    },
    mounted() {
      this.identifyCode = '';
@@ -138,11 +143,15 @@
                this.logining = false;
                setCookie('userinfo', res.data);
                setCookie('isLogin',true);
                setCookie('login_err_num', 0);
                this.$router.push({
                  path: '/'
                });
              })
              .catch(error => {
                // 记录错误次数 by lyzflash
                this.login_err_num += 1;
                setCookie('login_err_num', this.login_err_num);
                this.logining = false;
              });
          }