Login.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="login">
  3. <main class="login-main">
  4. <div class="login-title">
  5. <p>欢迎登录</p>
  6. <p>题库管理系统</p>
  7. </div>
  8. <div class="login-footer">
  9. Copyright &copy; 2021 <a href="https://www.qmth.com.cn">启明泰和</a>.
  10. </div>
  11. <div class="login-body" @keyup.enter="submit">
  12. <h1 class="login-body-title">题库管理系统</h1>
  13. <el-form ref="loginForm" :model="loginInfo" :rules="loginRules">
  14. <el-form-item prop="accountValue">
  15. <el-input
  16. v-model.trim="loginInfo.accountValue"
  17. placeholder="请输入账号"
  18. clearable
  19. >
  20. <i slot="prefix" class="icon icon-username"></i>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input
  25. v-model.trim="loginInfo.password"
  26. type="password"
  27. placeholder="请输入密码"
  28. clearable
  29. >
  30. <i slot="prefix" class="icon icon-password"></i>
  31. </el-input>
  32. </el-form-item>
  33. <el-form-item v-if="dialogVisible" prop="smsCode">
  34. <el-input
  35. v-model.trim="loginInfo.smsCode"
  36. placeholder="请输入短信验证码"
  37. clearable=""
  38. >
  39. <i slot="prefix" class="icon icon-code"></i>
  40. </el-input>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button
  44. class="login-submit-btn"
  45. type="danger"
  46. :disabled="isSubmit"
  47. @click="submit"
  48. >登录</el-button
  49. >
  50. </el-form-item>
  51. </el-form>
  52. </div>
  53. </main>
  54. </div>
  55. </template>
  56. <script>
  57. import { mapActions } from "vuex";
  58. import { USER_SIGNIN } from "../store/user";
  59. import { QUESTION_API } from "@/constants/constants";
  60. export default {
  61. data() {
  62. return {
  63. isSubmit: false,
  64. dialogVisible: false,
  65. loginInfo: {
  66. rootOrgId: "",
  67. domain: "",
  68. accountType: "COMMON_LOGIN_NAME",
  69. accountValue: "",
  70. password: "",
  71. smsCode: null,
  72. },
  73. loginRules: {
  74. accountValue: [
  75. {
  76. required: true,
  77. message: "请输入用户名",
  78. trigger: "change",
  79. },
  80. ],
  81. password: [
  82. {
  83. required: true,
  84. pattern: /^[a-zA-Z0-9_]{1,20}$/,
  85. message: "密码只能由数字、字母和下划线组成,长度1-20个字符",
  86. trigger: "change",
  87. },
  88. ],
  89. smsCode: [
  90. {
  91. required: true,
  92. message: "请输入短信验证码",
  93. trigger: "change",
  94. },
  95. ],
  96. },
  97. };
  98. },
  99. watch: {
  100. $route(to) {
  101. this.loginInfo.rootOrgId = to.query.orgId;
  102. },
  103. },
  104. created() {
  105. if (this.$route.hash && this.$route.hash.startsWith("#/access?")) {
  106. this.$router.push(this.$route.hash.slice(1));
  107. return;
  108. }
  109. this.loginInfo.domain =
  110. window.location.hostname.split(".")[0] + ".ecs.qmth.com.cn";
  111. sessionStorage.clear();
  112. var params = this.$route.query;
  113. this.loginInfo.rootOrgId = params.orgId;
  114. },
  115. methods: {
  116. ...mapActions([USER_SIGNIN]),
  117. async submit() {
  118. const valid = await this.$refs.loginForm.validate().catch(() => {});
  119. if (!valid) return;
  120. var url = QUESTION_API + "/auth/login";
  121. this.$httpWithMsg
  122. .post(url, this.loginInfo)
  123. .then((response) => {
  124. var user = response.data;
  125. this.USER_SIGNIN(user);
  126. this.$router.replace({ path: "/questions/tips" });
  127. this.$notify({
  128. message: "登录成功",
  129. type: "success",
  130. duration: 1000,
  131. });
  132. })
  133. .catch((error) => {
  134. if (error.response.data.code === "UQ-003100") {
  135. this.dialogVisible = true;
  136. }
  137. });
  138. },
  139. loginWithSms() {
  140. this.dialogVisible = false;
  141. this.submit();
  142. },
  143. },
  144. };
  145. </script>