index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="login flex row">
  3. <img class="left" src="../../../static/images/loginbg_left.png" />
  4. <div class="right flex column">
  5. <img class="logo" src="../../../static/images/logo.png" />
  6. <span class="welcome">欢迎登陆</span>
  7. <el-form class="form" ref="loginForm" :model="loginForm" label-width="80px" label-position="top"
  8. :rules="loginRules" hide-required-asterisk>
  9. <el-form-item label="账号:" prop="account">
  10. <el-input v-model="loginForm.account" @keyup.enter.native="handleLogin" placeholder="请输入账号" maxlength="20" clearable></el-input>
  11. </el-form-item>
  12. <el-form-item label="密码:" prop="password">
  13. <el-input v-model="loginForm.password" @keyup.enter.native="handleLogin" placeholder="请输入密码" maxlength="20" show-password clearable></el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button class="loginbtn blackbtn" :loading="loading" @click.native.prevent="handleLogin">登陆</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import {
  24. login
  25. } from "@/api/login";
  26. import store from '@/store/index'
  27. export default {
  28. name: "Login",
  29. data() {
  30. return {
  31. loginForm: {
  32. account: "",
  33. password: "",
  34. },
  35. loginRules: {
  36. account: [{
  37. required: true,
  38. trigger: "blur",
  39. message: "用户名不能为空"
  40. }],
  41. password: [{
  42. required: true,
  43. trigger: "blur",
  44. message: "密码不能为空"
  45. }]
  46. },
  47. loading: false,
  48. };
  49. },
  50. watch: {
  51. $route: {
  52. handler: function (route) {
  53. this.redirect = route.query && route.query.redirect;
  54. },
  55. immediate: true
  56. }
  57. },
  58. created() {},
  59. methods: {
  60. // 登录
  61. handleLogin() {
  62. this.$refs.loginForm.validate(valid => {
  63. if (valid) {
  64. this.loading = true;
  65. let params = {
  66. account: this.loginForm.account,
  67. password: this.$md5(this.loginForm.password)
  68. }
  69. login(params).then(res => {
  70. if (res.code == 0) {
  71. store.commit('SET_USER_INFO',res.data)
  72. store.commit('SET_USER_TOKEN',res.data.token)
  73. this.$router.push("/goods");
  74. }
  75. }).catch(()=>{
  76. this.loading=false
  77. });
  78. }
  79. });
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="less">
  85. .login {
  86. padding: 0 0 0 0 !important;
  87. background-color: white !important;
  88. }
  89. .left {
  90. width: 33%;
  91. }
  92. .right {
  93. width: 67%;
  94. background: url("../../../static/images/loginbg_right.png") no-repeat 100% 0%;
  95. background-size: contain;
  96. padding: 5%;
  97. .logo {
  98. width: 100px;
  99. height: auto;
  100. }
  101. .form {
  102. font-weight: bold;
  103. margin-top: 50px;
  104. margin-left: 50px;
  105. .el-input {
  106. width: 400px;
  107. }
  108. .loginbtn {
  109. width: 200px;
  110. margin-top: 20px;
  111. }
  112. }
  113. .welcome {
  114. color: #060101;
  115. font-size: x-large;
  116. font-weight: bold;
  117. margin-top: 10px;
  118. }
  119. }
  120. </style>