index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="login-container">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. :rules="loginRules"
  7. class="login-form"
  8. autocomplete="on"
  9. label-position="left"
  10. >
  11. <div class="title-container">
  12. <h3 class="title">
  13. {{ $t('Key539') }}
  14. </h3>
  15. </div>
  16. <el-form-item prop="user_name">
  17. <el-input
  18. v-model="loginForm.user_name"
  19. type="text"
  20. name="user_name"
  21. autocomplete="on"
  22. :placeholder="$t('username')"
  23. />
  24. </el-form-item>
  25. <el-form-item prop="password">
  26. <el-input
  27. v-model="loginForm.password"
  28. type="password"
  29. name="password"
  30. :placeholder="$t('password')"
  31. autocomplete="on"
  32. />
  33. </el-form-item>
  34. <el-row>
  35. <el-col :span="12">
  36. <el-button
  37. class="login-button"
  38. type="primary"
  39. :loading="loading"
  40. @click.native.prevent="handleLogin('TEACHER')"
  41. >
  42. {{ $t('Learn_TLogin') }}
  43. </el-button>
  44. </el-col>
  45. <el-col :span="12">
  46. <el-button
  47. class="login-button"
  48. type="primary"
  49. :loading="loading"
  50. @click.native.prevent="handleLogin('STUDENT')"
  51. >
  52. {{ $t('Learn_SLogin') }}
  53. </el-button>
  54. </el-col>
  55. </el-row>
  56. </el-form>
  57. </div>
  58. </template>
  59. <script>
  60. import { getConfigInformation } from '@/utils/index';
  61. export default {
  62. data() {
  63. const validateUsername = (rule, value, callback) => {
  64. if (value.length <= 0) {
  65. callback(new Error(this.$i18n.t('Learn_Login_user_warning')));
  66. } else {
  67. callback();
  68. }
  69. };
  70. const validatePassword = (rule, value, callback) => {
  71. if (value.length < 6) {
  72. callback(new Error(this.$i18n.t('Learn_Login_password_warning')));
  73. } else {
  74. callback();
  75. }
  76. };
  77. return {
  78. loginForm: {
  79. user_name: '',
  80. password: '',
  81. user_type: ''
  82. },
  83. loginRules: {
  84. user_name: [{ trigger: 'blur', validator: validateUsername }],
  85. password: [{ trigger: 'blur', validator: validatePassword }]
  86. },
  87. loading: false,
  88. redirect: null
  89. };
  90. },
  91. watch: {
  92. $router: {
  93. handler(router) {
  94. this.redirect = router.query && router.query.redirect;
  95. }
  96. }
  97. },
  98. created() {
  99. this.getConfig();
  100. this.updateWordPack({
  101. word_key_list: [
  102. 'Key539',
  103. 'password',
  104. 'username',
  105. 'Learn_TLogin',
  106. 'Learn_SLogin',
  107. 'Learn_Login_user_warning',
  108. 'Learn_Login_password_warning'
  109. ]
  110. });
  111. },
  112. methods: {
  113. async getConfig() {
  114. await getConfigInformation();
  115. },
  116. handleLogin(user_type) {
  117. this.$refs.loginForm.validate(valid => {
  118. if (valid) {
  119. this.loginForm.user_type = user_type;
  120. this.loading = true;
  121. this.$store
  122. .dispatch('user/login', { loginForm: this.loginForm })
  123. .then(() => {
  124. this.$router.push({ path: this.redirect || '/' });
  125. this.loading = false;
  126. this.$message.success('登录成功!');
  127. })
  128. .catch(() => {
  129. this.loading = false;
  130. });
  131. } else {
  132. return false;
  133. }
  134. });
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss">
  140. .login-container {
  141. width: 100%;
  142. min-height: 100%;
  143. overflow: hidden;
  144. background-color: $bac-color;
  145. .title-container {
  146. position: relative;
  147. .title {
  148. margin: 0 auto 40px;
  149. font-size: 26px;
  150. font-weight: bold;
  151. color: #999;
  152. text-align: center;
  153. }
  154. }
  155. .login-form {
  156. position: relative;
  157. width: 520px;
  158. max-width: 100%;
  159. padding: 160px 35px 0;
  160. margin: 0 auto;
  161. overflow: hidden;
  162. }
  163. .login-button {
  164. display: block;
  165. margin: 0 auto;
  166. }
  167. }
  168. </style>