index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. store.commit('CLEAR')
  60. },
  61. methods: {
  62. // 登录
  63. handleLogin() {
  64. this.$refs.loginForm.validate(valid => {
  65. if (valid) {
  66. this.loading = true;
  67. let params = {
  68. account: this.loginForm.account,
  69. password: this.$md5(this.loginForm.password)
  70. }
  71. login(params).then(res => {
  72. if (res.code == 0) {
  73. store.commit('SET_USER_INFO',res.data)
  74. store.commit('SET_USER_TOKEN',res.data.token)
  75. this.$router.push("/goods");
  76. }
  77. }).catch(()=>{
  78. this.loading=false
  79. });
  80. }
  81. });
  82. }
  83. }
  84. };
  85. </script>
  86. <style lang="less">
  87. .login {
  88. padding: 0 0 0 0 !important;
  89. background-color: white !important;
  90. }
  91. .left {
  92. width: 33%;
  93. }
  94. .right {
  95. width: 67%;
  96. background: url("../../../static/images/loginbg_right.png") no-repeat 100% 0%;
  97. background-size: contain;
  98. padding: 5%;
  99. .logo {
  100. width: 100px;
  101. height: auto;
  102. }
  103. .form {
  104. font-weight: bold;
  105. margin-top: 50px;
  106. margin-left: 50px;
  107. .el-input {
  108. width: 400px;
  109. }
  110. .loginbtn {
  111. width: 200px;
  112. margin-top: 20px;
  113. }
  114. }
  115. .welcome {
  116. color: #060101;
  117. font-size: x-large;
  118. font-weight: bold;
  119. margin-top: 10px;
  120. }
  121. }
  122. </style>