index.vue 4.13 KB
<template>
  <div class="bg">
    <div class="login-inner-bg login">
      <div class="user_style">
        <h3>欢迎登录</h3>
        <el-form
          :model="user"
          :rules="rules"
          ref="user"
          id="loginform"
          class="demo-ruleForm"
        >
          <el-form-item prop="account">
            <el-input v-model="user.account" placeholder="用户名"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              type="password"
              v-model="user.password"
              placeholder="登录密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-checkbox
              label="记住用户名"
              @change="checkUserName"
            ></el-checkbox>
          </el-form-item>
          <el-form-item id="login">
            <el-button type="primary" style="width: 100%" @click="login('user')"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { loginIn } from "@/api/login.js";
export default {
  name: "Login",
  data: function () {
    return {
      user: {
        account: "",
        password: "",
        checkStatus: false,
      },
      rules: {
        account: [{ required: true, message: "请填写帐号", trigger: "blur" }],
        password: [{ required: true, message: "请填写密码", trigger: "blur" }],
      },
    };
  },
  mounted: function () {
    // this.checkUserName();
  },
  methods: {
    //记住用户名
    checkUserName: function (flag) {
      this.user.checkStatus = flag;
      if (this.user.checkStatus) {
        localStorage.setItem("accountId", this.user.account);
        let name = localStorage.getItem("accountId");
        if (name === "") {
          return;
        } else {
          this.user.account = name;
        }
      } else {
        this.user.account = localStorage.getItem("accountId");
      }
    },
    login(user) {
      var self = this;
      this.$refs[user].validate((valid) => {
        if (valid) {
          loginIn(self.user.account, self.user.password)
            .then((res) => {
              if (res.status === 1) {
                //存储token
                sessionStorage.setItem("token", `Bearer ${res.content}`);
                //登录成功后需判断有无重定向,没有重定向则跳转首页
                this.$router.replace(this.$route.query.redirect || "/");
              } else {
                //错误处理
              }
            })
            .catch((error) => {
              // console.dir(error);
            });
        }
      });
    },
  },
  components: {},
};
</script>
<style scoped  lang="scss">
.bg {
  width: 100%;
  height: 100%;
  background: url(../../image/loginBg.jpg) no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
}

.login-inner-bg {
  background: url(../../image/loginBoxBg.png) no-repeat;
  width: 400px;
  height: 350px;
  margin: 35vh auto;
  overflow: hidden;
  background-size: 100% 100%;
  box-sizing: border-box;
  padding: 20px;
}

.login .user_style {
  margin: 40px 20px 0;
  h3{
    color: #fff;
    font-weight: normal;
    text-align: center;
    margin-bottom: 20px;
  }
}

.login .btn {
  width: 100%;
  height: 6vh;
  background-color: #00c2de;
  border-radius: 5px;
  font-size: 1.4vw;
  color: #ffffff;
}

.login .btn:hover {
  cursor: pointer;
  background-color: #2d8cf0;
}

#loginform .el-button {
  background: #409eff !important;
  color: #ffffff !important;
}

#loginform .el-button:hover {
  cursor: pointer !important;
  background-color: #2d8cf0 !important;
}
.inputUser .ivu-input {
  padding: 6px 24px !important;
  border: 1px solid #9f9f9f !important;
}

#loginform .el-input__inner {
  width: 100% !important;
  caret-color: #000 !important;
  color: #606266 !important;
  border-radius: 4px !important;
  border: 1px solid #67c23a !important;
  background: #fff !important;
  opacity: 1 !important;
}

#loginform .el-input__inner::-webkit-input-placeholder {
  /* WebKit browsers */
  color: #80807f !important;
}
.el-checkbox__label {
  color: #fff;
}
</style>
<style>
</style>