648540858
2022-11-17 a53dce38c2f58c0bfd37203e46dc57aa56025f45
web_src/src/components/Login.vue
@@ -22,7 +22,7 @@
          </div>
          <div class="container-login100-form-btn">
            <div class="wrap-login100-form-btn">
            <div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging" element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
              <div class="login100-form-bgbtn"></div>
              <button class="login100-form-btn" @click="login">登录</button>
            </div>
@@ -41,6 +41,7 @@
     return {
      isLoging: false,
      showPassword: false,
      loginLoading: false,
        username: '',
        password: ''
     }
@@ -65,10 +66,6 @@
     //登录请求
     toLogin(){
        //一般要跟后端了解密码的加密规则
        //这里例子用的哈希算法来自./js/sha1.min.js
        //需要想后端发送的登录参数
        let loginParam = {
           username: this.username,
@@ -77,15 +74,20 @@
      var that = this;
      //设置在登录状态
      this.isLoging = true;
      let timeoutTask = setTimeout(()=>{
        that.$message.error("登录超时");
        that.isLoging = false;
      }, 1000)
      this.$axios({
         method: 'get',
        url:"/api/user/login",
        params: loginParam
      }).then(function (res) {
        window.clearTimeout(timeoutTask)
        console.log(JSON.stringify(res));
          if (res.data.code == 0 && res.data.msg == "success") {
            that.$cookies.set("session", {"username": that.username}) ;
          if (res.data.code === 0 ) {
            that.$cookies.set("session", {"username": that.username,"roleId":res.data.data.role.id}) ;
            //登录成功后
            that.cancelEnterkeyDefaultAction();
            that.$router.push('/');
@@ -98,6 +100,8 @@
              });
          }
      }).catch(function (error) {
        console.log(error)
        window.clearTimeout(timeoutTask)
        that.$message.error(error.response.data.msg);
        that.isLoging = false;
      });