基于elementUI的封装的登录框

//账号密码输入框前面带图标 密码框自带小眼睛
<template>
  <div class="login_bg">
    <div class="login_box">
      <div class="login_title">庐陵湿地安全预警评价系统</div>
      <div class="login_item">
        <el-input
          placeholder="账号"
          oninput="value=value.replace(/[\u4e00-\u9fa5]/g, '')"
          v-model="userName"
        >
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
      </div>
      <div class="login_item">
        <el-input
          placeholder="密码"
          type="password"
          oninput="value=value.replace(/[\u4e00-\u9fa5]/g, '')"
          v-model="passWord"
          :show-password="true"
        >
          <i slot="prefix" class="el-input__icon el-icon-set-up"></i>
        </el-input>
      </div>
      <div class="login_item">
        <el-button type="primary" style="width: 100%" @click="submit"
          >登录</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      userName: "",
      passWord: "",
    }
  },
  mounted() {
    window.addEventListener("keydown", this.keyLogin)
  },
  destroyed() {
    window.removeEventListener("keydown", this.keyLogin, false)
  },
  methods: {
    keyLogin(event) {
      if (event.keyCode == 13)
        //回车键的键值为13
        this.submit() //调用登录按钮的登录事件
    },
    submit() {
      if (this.userName && this.passWord) {
        this.$api
          .login({
            menuType: 0,
            suLoginname: this.userName,
            suPwd: this.passWord,
          })
          .then((res) => {
            console.log(res)
            // this.$setData("token", "")
            this.$setData(
              "permissionList",
              JSON.stringify(res.data.data.permissionList)
            )
            this.$setData("token", res.headers.token)
            this.$setData("userInfo", JSON.stringify(res.data.data.userInfo))
            this.$message.success("登录成功!")
            setTimeout(() => {
              this.$router.push("/")
            }, 1000)
          })
      } else {
        this.$message.error("账号密码不能为空。")
      }
    },
  },
}
</script>
<style lang="less" scoped>
.login_bg {
  width: 100%;
  height: 100%;
  display: flex;
  //   background: #000;
  justify-content: center;
  align-items: center;
  background: url(../../assets/login_bg.jpg) center no-repeat;
  background-size: cover;
  .login_title {
    font-size: 40px;
    color: #fff;
    margin-bottom: 30px;
    font-weight: bold;
  }
  .login_box {
    width: 500px;
    height: 300px;
    // background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .login_item {
    width: 250px;
    padding: 20px 20px 0px 20px;
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值