Surpriseplus
2022-11-12 50f52beb0ed100105166f62027cd0b15e6b596dc
src/components/login.vue
@@ -153,15 +153,15 @@
<script>
// import { login } from '../utils/api'
import validCode from "./verificationCode.vue";
import { mapActions } from "vuex";
import validCode from './verificationCode.vue';
import { mapActions } from 'vuex';
export default {
  components: { validCode },
  data() {
    let validUserName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("用户名不能为空"));
        return callback(new Error('用户名不能为空'));
      } else {
        callback();
      }
@@ -169,7 +169,7 @@
    let validPassword = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
        return callback(new Error('密码不能为空'));
      } else {
        callback();
      }
@@ -177,25 +177,25 @@
    const checkValidCode = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入验证码"));
        callback(new Error('请输入验证码'));
      } else if (value.toUpperCase() !== this.validCode.toUpperCase()) {
        callback(new Error("验证码不正确"));
        callback(new Error('验证码不正确'));
      } else {
        callback();
      }
    };
    return {
      validCode: "",
      validCode: '',
      loading: false,
      loginForm: {
        uid: "admin",
        pwd: "Admin@123",
        uid: 'admin',
        pwd: 'Admin@123',
      },
      rules: {
        uid: [{ validator: validUserName, trigger: "blur" }],
        pwd: [{ validator: validPassword, trigger: "blur" }],
        validCode: [{ validator: checkValidCode, trigger: "blur" }],
        uid: [{ validator: validUserName, trigger: 'blur' }],
        pwd: [{ validator: validPassword, trigger: 'blur' }],
        validCode: [{ validator: checkValidCode, trigger: 'blur' }],
      },
    };
  },
@@ -204,7 +204,7 @@
  },
  methods: {
    //   获取vuex中Actions里的方法
    ...mapActions(["login", "getpublickey"]),
    ...mapActions(['login', 'getpublickey']),
    getCode(data) {
      console.log(data);
      this.validCode = data; //在data中定义一个 validCode:'',用来记录验证码。
@@ -214,20 +214,20 @@
        if (valid) {
          this.loading = true;
          this.login(this.loginForm)
            .then(response => {
             this.$router.push("/")
            .then((response) => {
              this.$router.push('/');
              this.loading = false;
              //调用录接口
            })
            .catch(response => {
            .catch((response) => {
              this.loading = false;
            });
          //如果登录失败,需要刷新验证码的
          this.$refs.refresh.createdCode();
          this.validCode = ""; //清空验证码输入框的内容
          this.validCode = ''; //清空验证码输入框的内容
        } else {
          console.log("error submit!!");
          console.log('error submit!!');
          return false;
        }
      });
@@ -238,7 +238,7 @@
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped >
<style scoped>
.container {
  width: 100%;
  height: 100%;