2019-7-29--登陆验证

upitem() {
      console.log("1 :", 1);
      let user = this.username;
      let pwd = this.password;
      if (user == "" || pwd == "") {
        this.$toast("账号或密码不能为空!!");
      } else {
        let pattuser = /^[A-z]\w{2,14}$/;
        let pattpwd = /^\w{2,15}$/;
        if (!pattuser.test(user)) {
          this.$toast("用户名必须满足字符开头,\n 且长度在2-15为之间!!");
        } else {
          if (!pattpwd.test(pwd)) {
            this.$toast("密码必须为2-15位非特殊字符!");
          } else {
            var params = new URLSearchParams();
            params.append("userName", user);
            params.append("password", pwd);
            this.axios
              .post("http://www.doubleb.fun/api/checkLogin.php", params)
              .then(res => {
                if (res.data.status == "200") {
                  // console.log('res :', res);
                  this.uid = res.data.uid;
                  document.cookie =
                    "userState=" + res.data.userToken + "&uid=" + this.uid;
                  this.$toast("登录成功");
                  this.show = false;
                  //   setTimeout(() => {
                  //     this.addcar();
                  //   }, 50);
                } else {
                  this.$toast("登录失败!! \n 请检查用户名或者密码后重新输入。");
                }

                console.log(res);
              })
              .catch(err => {
                console.error(err);
              });
          }
        }
      }
    }

  

猜你喜欢

转载自www.cnblogs.com/web-xpy/p/11262522.html