index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="login">
  3. <main class="login-container">
  4. <div class="title">登录</div>
  5. <el-form ref="loginForm" :model="form" :rules="rules" label-position="right">
  6. <el-form-item prop="user_name" label="用户名">
  7. <el-input v-model="form.user_name" />
  8. </el-form-item>
  9. <el-form-item prop="password" label="密码">
  10. <el-input v-model="form.password" type="password" show-password />
  11. </el-form-item>
  12. <el-form-item prop="verification_code_image_text" class="verification-code" label="验证码">
  13. <el-input v-model="form.verification_code_image_text" @keyup.enter.native="signIn" />
  14. <el-image
  15. v-if="image_content_base64.length > 0"
  16. :src="`data:image/jpg;base64,${image_content_base64}`"
  17. @click="updateVerificationCode"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button class="submit" type="primary" @click="signIn">登录</el-button>
  22. </el-form-item>
  23. <el-form-item>
  24. <div class="protocol">
  25. <span>
  26. <el-checkbox v-model="isAgree" /> 我已阅读并同意<span style="color: #4d78ff">《用户协议》</span>
  27. </span>
  28. <span style="color: #4d78ff">忘记密码?</span>
  29. </div>
  30. </el-form-item>
  31. </el-form>
  32. </main>
  33. </div>
  34. </template>
  35. <script>
  36. import md5 from 'md5';
  37. import { GetVerificationCodeImage, GetLogo } from '@/api/app';
  38. import { setConfig } from '@/utils/auth';
  39. export default {
  40. name: 'LoginPage',
  41. data() {
  42. return {
  43. isAgree: true, // 是否同意用户协议
  44. form: {
  45. user_type: 'TEACHER',
  46. user_name: '',
  47. password: '',
  48. is_password_md5: 'true',
  49. verification_code_image_id: '',
  50. verification_code_image_text: '',
  51. },
  52. rules: {
  53. user_name: [
  54. {
  55. required: true,
  56. message: '请输入用户名',
  57. trigger: 'blur',
  58. },
  59. ],
  60. password: [
  61. {
  62. required: true,
  63. message: '请输入密码',
  64. trigger: 'blur',
  65. },
  66. ],
  67. verification_code_image_text: [{ required: true, trigger: 'blur', message: '验证码不能为空' }],
  68. },
  69. image_content_base64: '',
  70. };
  71. },
  72. created() {
  73. this.updateVerificationCode();
  74. this.getLogo();
  75. },
  76. methods: {
  77. updateVerificationCode() {
  78. GetVerificationCodeImage().then(({ image_id, image_content_base64: image }) => {
  79. this.form.verification_code_image_id = image_id;
  80. this.image_content_base64 = image;
  81. });
  82. },
  83. getLogo() {
  84. GetLogo().then((res) => {
  85. setConfig(res);
  86. });
  87. },
  88. signIn() {
  89. this.$refs.loginForm.validate((valid) => {
  90. if (!valid) return false;
  91. let _form = { ...this.form, password: md5(this.form.password).toUpperCase() };
  92. this.$store
  93. .dispatch('user/login', _form)
  94. .then(() => {
  95. this.$router.push({ path: '/' });
  96. })
  97. .catch(() => {
  98. this.updateVerificationCode();
  99. });
  100. });
  101. },
  102. },
  103. };
  104. </script>
  105. <style lang="scss" scoped>
  106. .login {
  107. width: 100%;
  108. height: 100%;
  109. overflow: hidden;
  110. background: #2148c0 url('~@/assets/login/login-bg.png') no-repeat center center / cover;
  111. &-container {
  112. padding: 200px;
  113. .title {
  114. margin-bottom: 28px;
  115. font-size: 24px;
  116. color: #fff;
  117. text-align: center;
  118. }
  119. :deep .el-form {
  120. max-width: 400px;
  121. padding: 24px 32px;
  122. margin: 0 auto;
  123. background-color: #fff;
  124. border-radius: 16px;
  125. &-item {
  126. &__label {
  127. margin-bottom: 8px;
  128. font-size: 18px;
  129. font-weight: bold;
  130. color: #000;
  131. &::before {
  132. display: none;
  133. }
  134. }
  135. }
  136. .el-input {
  137. &__inner {
  138. height: 40px;
  139. line-height: 40px;
  140. background-color: #fff;
  141. }
  142. }
  143. .verification-code {
  144. display: flex;
  145. flex-direction: column;
  146. label {
  147. text-align: left;
  148. }
  149. .el-input {
  150. width: calc(100% - 112px);
  151. margin-right: 10px;
  152. }
  153. .el-image {
  154. height: 38px;
  155. vertical-align: bottom;
  156. cursor: pointer;
  157. }
  158. }
  159. .submit {
  160. width: 100%;
  161. }
  162. .protocol {
  163. display: flex;
  164. justify-content: space-between;
  165. font-size: 12px;
  166. color: #000;
  167. }
  168. .el-form-item--small.el-form-item:last-child {
  169. margin-bottom: 0;
  170. }
  171. }
  172. .not-tips {
  173. margin-top: 20px;
  174. font-size: 12px;
  175. color: #fff;
  176. text-align: center;
  177. cursor: pointer;
  178. }
  179. }
  180. }
  181. </style>