panlinlin
2021-04-12 27df8bd84cfceb4154bb7543a7d1fc58fc8d1b04
web_src/src/components/Login.vue
@@ -10,16 +10,14 @@
        <div class="log-logo">Welcome!</div>
        <div class="log-text"></div>
    </div>
    <div class="log-email">
    <div class="log-email" v-loading="isLoging" >
        <input type="text" placeholder="用户名" :class="'log-input' + (username==''?' log-input-empty':'')" v-model="username"><input type="password" placeholder="密码" :class="'log-input' + (password==''?' log-input-empty':'')"  v-model="password">
        <a href="javascript:;" class="log-btn" @click="login" >登录</a>
    </div>
    <Loading v-if="isLoging" marginTop="-30%"></Loading>
</div>
</template>
<script>
import Loading from './Loading.vue'
import crypto from 'crypto'
export default {
  name: 'Login',
@@ -30,18 +28,14 @@
        password: ''
     }
  },
  components:{
    Loading
  },
  created(){
  var that = this;
  document.onkeydown = function(e) {
    var key = window.event.keyCode;
    if (key == 13) {
      that.login();
    var that = this;
    document.onkeydown = function(e) {
      var key = window.event.keyCode;
      if (key == 13) {
        that.login();
      }
    }
  }
  },
  methods:{
@@ -67,7 +61,7 @@
      //设置在登录状态
      this.isLoging = true;
      this.$axios.get("/auth/login",{
      this.$axios.get("/api/user/login",{
        params: loginParam
      } )
      .then(function (res) {
@@ -75,24 +69,38 @@
          if (res.data == "success") {
            that.$cookies.set("session", {"username": that.username}) ;
            //登录成功后
            that.cancelEnterkeyDefaultAction();
            that.$router.push('/');
          }else{
            that.isLoging = false;
            that.$message({
                  showClose: true,
                  message: '登录失败,用户名或密码错误',
                  type: 'error'
              });
          }
      })
      .catch(function (error) {
        console.log(error);
        that.$message.error(error.response.statusText);
        that.isLoging = false;
      });
    },
     setCookie: function (cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toUTCString();
                console.info(cname + "=" + cvalue + "; " + expires);
                document.cookie = cname + "=" + cvalue + "; " + expires;
                console.info(document.cookie);
            },
    setCookie: function (cname, cvalue, exdays) {
      var d = new Date();
      d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
      var expires = "expires=" + d.toUTCString();
      console.info(cname + "=" + cvalue + "; " + expires);
      document.cookie = cname + "=" + cvalue + "; " + expires;
      console.info(document.cookie);
    },
    cancelEnterkeyDefaultAction: function() {
        document.onkeydown = function(e) {
        var key = window.event.keyCode;
        if (key == 13) {
          return false;
        }
      }
    }
  }
}
</script>