index.vue 6.64 KB
<template>
  <div class="bg">
    <div class="title">
      <img src="../../image/bdclogo.png" alt="">
      <h2>{{ productName }}</h2>
    </div>
    <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" @keyup.native="login('user')" v-model="user.password"
              placeholder="请输入密码" show-password></el-input>
          </el-form-item>
          <el-form-item prop="yz">
            <el-input class="yz" @keyup.native="login('user')" v-model="user.yz"
              placeholder="请输入验证码"></el-input>
          </el-form-item>
          <el-form-item class="login-btn">
            <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: "",
          yz: "",
          checkStatus: false,
        },
        productName: "",
        rules: {
          account: [{ required: true, message: "请填写帐号", trigger: "blur" }],
          password: [{ required: true, message: "请填写密码", trigger: "blur" }],
        },
      };
    },
    created () {
      const params = {};
      const queryOptions = {
        conditionGroup: {
          conditions: [
            {
              property: "code",
              value: "BDCSBPT",
              operator: "EQ",
            },
          ],
          queryRelation: "AND",
        },
      };
      params.queryOptions = JSON.stringify(queryOptions);
      //根据子系统code获取子系统详细信息
      getAction(api.subsystem, params).then((res) => {
        if (res.status === 1) {
          this.productName = res.content[0].name;
          this.$store.dispatch("products/setData", res.content[0].code);

          sessionStorage.setItem("products", res.content[0].code)
        } 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) {
                  this.$store.dispatch('business/setInitRules', "layout1")
                  //存储token
                  sessionStorage.setItem("token", `Bearer ${res.content}`);
                  //登录成功后需判断有无重定向,没有重定向则跳转首页
                  this.$router.replace(this.$route.query.redirect || "/");
                } else {
                  console.log(res);
                  this.$message.error({ message: res.message })
                }
              })
              .catch((error) => {
                // console.dir(error);
              });
          }
        });
      },
    },
    components: {},
  };
</script>
<style scoped lang="scss">
  .username,
  .password,
  .yz {
    position: relative;

    &:before {
      content: "";
      display: block;
      width: 16px;
      height: 16px;
      position: absolute;
      left: 10px;
      top: 7px;
      background-size: 100% 100%;
    }

    /deep/ .el-input__inner {
      color: #000 !important;
      text-indent: 24px;
      // border: 1px solid rgba(11, 161, 248, 0.4);
      // background-color: rgba(6, 135, 205, 0.3) !important;
    }
  }

  .username::before {
    background-image: url(../../image/userlogo.png);
  }

  .password::before {
    background-image: url(../../image/passlogo.png);
  }
  .yz::before {
    background-image: url(../../image/yzlogo.png);
  }

  .bg {
    width: 100%;
    height: 100%;
    min-width: 1440px;
    min-height: 560px;
    background: url(../../image/loginBoxsb.png) no-repeat;
    background-size: 100% 100%;
    overflow: hidden;
    position: relative;
  }
  .title {
    width: 24%;
    height: 6%;
    top: 20%;
    right: 38%;
    position: absolute;
    img {
      width: 60px;
      height: 60px;
      top: 0%;
      left: 2%;
      position: absolute;
    }
    h2 {
      top: 25%;
      left: 22%;
      position: absolute;
      width: 383px;
      height: 42px;
      font-size: 28px;
      font-weight: 600;
      color: #ffffff;
      text-shadow: 0px 4px 4px #002c95;
    }
  }
  .login-inner-bg {
    background: white;
    width: 24.6%;
    height: 47%;
    min-width: 360px;
    min-height: 380px;
    top: 30%;
    right: 38%;
    position: absolute;
    background-size: 100% 100%;
    box-sizing: border-box;
    padding: 56px;
  }

  .login {
    .user_style {
      h3 {
        font-weight: normal;
        text-align: center;
        margin: -10px auto 28px;
        font-weight: 400;
        width: 125px;
        height: 29px;
        font-size: 20px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #333333;
      }
    }

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

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

  .login #loginform {
    .el-form-item {
      margin-bottom: 24px !important;
    }

    .login-btn {
      margin-top: 30px !important;
    }

    .el-button {
      font-size: 18px;
      border-radius: 0;
      background: #4162d8 !important;
      color: #ffffff !important;
      cursor: pointer !important;
    }

    .el-input__inner {
      width: 100% !important;
    }

    .el-checkbox__label {
      color: #fff;
    }
  }

  .inputUser .ivu-input {
    padding: 6px 24px !important;
    border: 1px solid #9f9f9f !important;
  }
</style>