index.vue 4.8 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
              class="username"
              v-model="user.account"
              placeholder="用户名"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              type="password"
              class="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";
import { api, getAction } from "@/api/manageApi";
export default {
  name: "Login",
  data() {
    return {
      user: {
        account: "",
        password: "",
        checkStatus: false,
      },
      rules: {
        account: [{ required: true, message: "请填写帐号", trigger: "blur" }],
        password: [{ required: true, message: "请填写密码", trigger: "blur" }],
      },
    };
  },
  created() {
    const params = {};
    const queryOptions = {
      conditionGroup: {
        conditions: [
          {
            property: "code",
            value: "BDCJGPT",
            operator: "EQ",
          },
        ],
        queryRelation: "AND",
      },
    };
    params.queryOptions = JSON.stringify(queryOptions);
    //根据子系统code获取子系统详细信息
    getAction(api.subsystem, params).then((res) => {
      if (res.status === 1) {
        this.$store.dispatch("products/setData", res.content[0]);
      } else {
        this.$message.error({ message: res.message, showClose: true });
      }
    });
  },
  mounted() {
    // 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);
            });
        }
      });
    },
  },
  computed: {
    productName() {
      return this.$store.state.products.products.name;
    },
  },
  components: {},
};
</script>
<style scoped lang="scss">
.username,
.password {
  /deep/ .el-input__inner {
    border: 1px solid #6bc1fc;
    background-color: transparent !important;
  }
}
.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;
}

.el-checkbox__label {
  color: #fff;
}
</style>