MyLogin.vue 2.8 KB
Newer Older
1
<template>
2 3 4 5 6 7
  <div class="login-container">
    <div class="login-box">
      <!-- 头像区域 -->
      <div class="text-center avatar-box">
        <img src="../assets/kwan.png" class="img-thumbnail avatar" alt="kwan的解忧杂货铺"/>
      </div>
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
      <!-- 表单区域 -->
      <div class="form-login p-4">
        <!-- 登录名称 -->
        <div class="form-group form-inline">
          <label for="username">登录名称</label>
          <input type="text" class="form-control ml-2" id="username" placeholder="请输入登录名称" autocomplete="off"
                 v-model.trim="username"/>
        </div>
        <!-- 登录密码 -->
        <div class="form-group form-inline">
          <label for="password">登录密码</label>
          <input type="password" class="form-control ml-2" id="password" placeholder="请输入登录密码" v-model.trim="password"/>
        </div>
        <!-- 登录和重置按钮 -->
        <div class="form-group form-inline d-flex justify-content-end">
          <button type="button" class="btn btn-secondary mr-2" @click="reset">重置</button>
          <button type="button" class="btn btn-primary" @click="login">登录</button>
        </div>
      </div>
    </div>
  </div>
30 31 32 33
</template>

<script>
export default {
34 35 36 37 38 39 40 41 42 43 44
  name: 'MyLogin',
  data() {
    return {
      username: '',
      password: '',
    }
  },
  methods: {
    reset() {
      this.username = ''
      this.password = ''
45
    },
46
    login() {
47
      if (this.username === 'admin' && this.password === '888888') {
48 49 50 51 52 53 54 55 56 57
        // 登录成功
        // 1. 存储 token
        localStorage.setItem('token', 'Bearer xxxx')
        // 2. 跳转到后台主页
        this.$router.push('/home')
      } else {
        // 登录失败
        localStorage.removeItem('token')
        this.errorMsg('登录失败,请检查您的用户名或密码;由于用户名密码是写死的,需要在项目中查看!!!')
      }
58
    },
59 60 61 62 63 64 65 66
    errorMsg(msg) {
      this.$message({
        showClose: true,
        message: msg,
        type: 'error',
      })
    },
  },
67 68 69 70 71
}
</script>

<style lang="less" scoped>
.login-container {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  background-color: #35495e;
  height: 100%;

  .login-box {
    width: 400px;
    height: 250px;
    background-color: #fff;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);

    .form-login {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      box-sizing: border-box;
    }
  }
94 95 96
}

.form-control {
97
  flex: 1;
98 99 100
}

.avatar-box {
101 102 103 104 105 106 107 108 109 110 111
  position: absolute;
  width: 100%;
  top: -65px;
  left: 0;

  .avatar {
    width: 120px;
    height: 120px;
    border-radius: 50% !important;
    box-shadow: 0 0 6px #efefef;
  }
112
}
113
</style>