login.vue 4.23 KB
<!--
 * @Date: 2024-10-18 18:00:47
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-10-25 13:49:38
 * @FilePath: /hager/src/views/user/login.vue
 * @Description: 文件描述
-->
<template>
  <div :class="['hager-login-page', is_xs ? 'xs' : '']">
    <div class="input-title">用户登录</div>
    <div style="padding: 1rem 1.5rem 1rem 1rem;">
      <hagerInput type="email" required v-model="email" placeholder="请输入注册邮箱地址" />
      <hagerInput type="pwd" required v-model="pwd" placeholder="请输入登录密码" />
      <!-- TODO: 记住密码和忘记密码业务显示的问题? -->
      <div class="pwd-box">
        <!-- <div><el-checkbox v-model="checked">记住密码</el-checkbox></div> -->
        <div><span @click="goToReset">忘记/修改密码?</span></div>
      </div>
    </div>
    <div class="login-footer">
      <div class="submit-btn" @click="onSubmit">立即登录</div>
      <div class="login-subsidiary">
        <div class="login">没有账号,<span @click="goToRegister">注册新账号</span></div>
      </div>
    </div>
  </div>
</template>

<script>
import mixin from 'common/mixin';
import hagerInput from '@/components/common/hagerInput.vue';
import $ from 'jquery';
import { loginAPI } from '@/api/hager';
import { MessageBox, Message } from 'element-ui';

export default {
  mixins: [mixin.init],
  data () {
    return {
      email: '',
      pwd: '',
      checked: false
    }
  },
  mounted () {
    if ($('#router-view').outerHeight() < $('.user-box').height()) {
      $('#router-view').height($('.user-box').outerHeight())
    }
  },
  methods: {
    async onSubmit () {
      if (!this.email) {
        Message({
          type: 'error',
          message: '邮箱地址不能空'
        });
        return;
      }
      // 检验邮箱地址有效性
      if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.email)) {
        Message({
          type: 'error',
          message: '邮箱地址格式不正确'
        });
        return;
      }
      if (!this.pwd) {
        Message({
          type: 'error',
          message: '登录密码不能空'
        });
        return;
      }
      const { code, msg } = await loginAPI({ email: this.email, password: this.pwd });
      if (code) {
        Message({
          type: 'success',
          message: msg
        });
        this.$router.push('/');
      }
    },
    goToRegister () {
      this.$router.push('/user/register');
    },
    goToReset () {
      this.$router.push('/user/reset');
    }
  }
}
</script>

<style lang="less" scoped>
  .hager-login-page {
    padding: 2rem 0.5rem 0;
    display: flex;
    flex-direction: column;
    &.xs {
      background: linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url('https://cdn.ipadbiz.cn/hager/img/user/l-bg.png');
      background-size: 80% 50%;
      background-position: bottom;
      background-repeat: no-repeat;
      padding-top: 0;
      padding-bottom: 5rem;
    }
    .input-title {
      color: @secondary-color;
      font-weight: bold;
      font-size: 1.25rem;
      text-align: center;
    }
    .pwd-box {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      margin-top: 1rem;
      font-size: 0.85rem;
      padding-left: 1rem;
      span {
        color: @primary-color;
        font-weight: bold;
        &:hover {
          cursor: pointer;
        }
      }
    }
    .submit-btn {
      background-color: @secondary-color;
      color: #FFF;
      padding: 0.5rem 1rem;
      text-align: center;
      border-radius: 5px;
      &:hover {
        cursor: pointer;
      }
    }
    .login-footer {
      padding: 0 1rem 1rem 2rem;
      .login-subsidiary {
        text-align: center;
        font-size: 0.85rem;
        margin-top: 1rem;
        span {
          color: @primary-color;
          text-decoration: underline;
          font-weight: bold;
          &:hover {
            cursor: pointer;
          }
        }
      }
    }
  }

  :deep(.el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner) {
    background-color: #009FE5;
    border-color: #009FE5;
  }

  :deep(.el-checkbox__input.is-checked+.el-checkbox__label) {
    color: #009FE5;
  }
</style>