login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div id="login">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <div class="w_1200">
  6. <el-col :span="24" class="one">
  7. <el-col :span="24" class="txt">商城管理登陆</el-col>
  8. <el-col :span="24" class="form">
  9. <el-form :model="form" :rules="rules" ref="form">
  10. <el-form-item label="" prop="account">
  11. <el-input placeholder="账号" v-model="form.account" @keyup.enter.native="onSubmit('form')">
  12. <i slot="prefix" class="el-input__icon el-icon-user-solid"></i>
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item label="" prop="password">
  16. <el-input placeholder="密码" v-model="form.password" type="password" auto-complete="off" @keyup.enter.native="onSubmit('form')">
  17. <i slot="prefix" class="el-input__icon el-icon-lock"></i>
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item class="btn">
  21. <el-button type="primary" @click="onSubmit('form')">登录</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </el-col>
  25. <el-col :span="24" class="other">
  26. <el-button type="text" style="color: blue; font-size: 14px" @click="toReset()">忘记密码?</el-button>
  27. </el-col>
  28. </el-col>
  29. </div>
  30. </el-col>
  31. </el-row>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapState, createNamespacedHelpers } from 'vuex';
  36. const { mapActions: maU } = createNamespacedHelpers('admin');
  37. const { mapActions: admins } = createNamespacedHelpers('admins');
  38. const _ = require('lodash');
  39. export default {
  40. name: 'login',
  41. props: {},
  42. components: {},
  43. data: function () {
  44. return {
  45. form: {},
  46. rules: {
  47. account: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
  48. password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
  49. },
  50. };
  51. },
  52. created() {},
  53. methods: {
  54. ...maU(['login']),
  55. ...admins(['email']),
  56. onSubmit(formName) {
  57. this.$refs[formName].validate(async (valid) => {
  58. if (valid) {
  59. const res = await this.login(this.form);
  60. if (!res) {
  61. this.$message({ type: `error`, message: `登陆失败` });
  62. } else {
  63. if (res.errcode !== 0) {
  64. this.$message({ type: 'error', message: `${res.errmsg}` });
  65. } else {
  66. this.$router.push({ path: '/' });
  67. }
  68. }
  69. } else {
  70. console.log('error submit!!');
  71. return false;
  72. }
  73. });
  74. },
  75. async toReset() {
  76. if (this.form.account == undefined || this.form.account == '') {
  77. this.$message.error('请输入账号');
  78. } else {
  79. this.$confirm('忘记密码,是否确认重置密码?', '提示', {
  80. confirmButtonText: '确定',
  81. cancelButtonText: '取消',
  82. type: 'warning',
  83. }).then(async () => {
  84. const res = await this.email({ account: this.form.account });
  85. if (this.$checkRes(res)) {
  86. this.$message({ type: `success`, message: `重置密码成功` });
  87. }
  88. });
  89. }
  90. },
  91. },
  92. computed: {
  93. ...mapState(['user']),
  94. },
  95. metaInfo() {
  96. return { title: this.$route.meta.title };
  97. },
  98. watch: {
  99. test: {
  100. deep: true,
  101. immediate: true,
  102. handler(val) {},
  103. },
  104. },
  105. };
  106. </script>
  107. <style lang="less" scoped>
  108. .main {
  109. display: flex;
  110. flex-direction: column;
  111. width: 100%;
  112. height: 100vh;
  113. overflow: hidden;
  114. background: url('~@/assets/login-background.jpg');
  115. background-repeat: no-repeat;
  116. background-size: 100%;
  117. .one {
  118. background-color: #ffffff;
  119. border-radius: 5px;
  120. padding: 10px 20px;
  121. margin: 70% 0 0 0;
  122. .txt {
  123. text-align: center;
  124. font-size: 20px;
  125. font-weight: bold;
  126. margin: 15px 0;
  127. }
  128. .form {
  129. .btn {
  130. text-align: center;
  131. .el-button {
  132. width: 100%;
  133. }
  134. }
  135. }
  136. .other {
  137. text-align: center;
  138. }
  139. }
  140. }
  141. </style>