Login.vue 3.6 KB
<template>
  <div class="register">

      <h2 @click="back1"><</h2>
      <div class="header">
        <img src="../assets/01.png" alt="">
      </div>
       <div class="center" type=">
          <form action="" method="post" onsubmit="return checkForm(this)">


         <input id="p_tel" type="text" name="p_tel" v-model="loginForm.mobile" placeholder="请输入手机号"/><hr/>

          <input id="p_cardid" type="text" name="p_cardid" v-model="loginForm.password" placeholder="请输入密码" /><hr/>
          <div class="footer">
            <p @click="goForget">忘记密码</p><p @click="goRegister">注册</p>
          </div>

          <button type="submit" @click="goLoginSuccessful">登录</button>
</form>
       </div>

  </div>
</template>
<script>
import { mapMutations } from 'vuex'
export default {
  name: 'register',
  components: {

  },
  data () {
    return {
      loginForm: {
        mobile: '',
        password: ''

      }

    }
  },
  mounted: function () {

  },
  methods: {
    back1 () {
      this.$router.go(-1)
    },
    goForget () {
      this.$router.push('/forget')
    },
    goRegister () {
      this.$router.push('/register')

    },
    ...mapMutations(['changeLogin']),
    goLoginSuccessful () {
       this.$router.push('/loginSuccessful')
        let _this = this
       if (this.loginForm.mebile === '' || this.loginForm.passeord === '') {
          alert('手机号和密码不能为空')
       } else {
        _this.$axios({
          method: 'post',
          url: 'api/Login/login',
          data: _this.loginForm
        }).then(res => {

          console.log(res.data)
          _this.userToken = 'token' + res.data.data.body.token
          _this.changeLogin({ Authorization: _this.userToken })
          localStorage.removeItem('Authorization')
          _this.$router.push('/loginSuccessful')
          alert('登录成功')
        }).catch(error => {
          alert('手机号或密码错误')
          console.log(error)
        })
      }
     }
      }
  }
 </script>
<style lang="scss" scoped>
 .register{
    width:100%;
    height:100%;
    background:#11A7FC;
    padding-top:5%;
    padding-left:5%;
    h2{
      font-size:.2rem;
      color:#fff;
      margin-bottom:.5rem;
    }
    .van-dialog .bar{
      width:90%;
      height:1.2rem;background:rgba(217,241,255,1);;

      margin-left:5%;
      border-radius:.2rem;
      padding-top:.2rem;
      margin-bottom:.2rem;
      margin-top:.2rem;
      p{
        color:#11A7FC;
        text-align:center;
        margin-bottom:.2rem;

      }
     span{
        color:#11A7FC;
        text-align:center;
        display:inline-block;
     }

    }
    p{
      text-align:center;
      // margin-top:0.2rem;
    }
    .header{
      width:60%;
      height:.4rem;
      margin-left:25%;

    }
     .center{
       width:80%;
       margin-top:.7rem;
       margin-left:7%;
       input{
          width:100%;
          height:.5rem;
          font-size:.2rem;
          display:block;
          background-color:#11A7FC;
          border:none;
          color:#fff;
          padding-left:4%;

       }
       hr{
         color:#fff;
         opacity:0.3;
       }
       .footer{
          width:100%;
          height:0.6rem;
          display:flex;
          justify-content:space-between;
           p{
             font-size:.2rem;
             color:#fff;
             line-height:.6rem;
           }
       }
       button{
         width:100%;
         height:.5rem;
         font-size:0.2rem;
         border-radius:.2rem;
         color:#11A7FC;
         font-weight:bold;
         border:none;
       }
     }
 }

</style>