Login.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="login login-box">
  3. <div class="login-body">
  4. <div class="login-title">
  5. <h1>逸教云</h1>
  6. </div>
  7. <div class="login-form">
  8. <el-form ref="loginForm" :model="loginModel" :rules="loginRules">
  9. <el-form-item prop="loginName">
  10. <el-input
  11. v-model.trim="loginModel.loginName"
  12. placeholder="请输入账号"
  13. clearable
  14. >
  15. <i class="icon icon-user" slot="prefix"></i>
  16. </el-input>
  17. </el-form-item>
  18. <el-form-item prop="password">
  19. <el-input
  20. type="password"
  21. v-model.trim="loginModel.password"
  22. placeholder="请输入密码"
  23. clearable
  24. >
  25. <i class="icon icon-lock" slot="prefix"></i
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button
  30. style="width:116px;"
  31. type="primary"
  32. :disabled="isSubmit"
  33. @click="submit('loginForm')"
  34. >登录</el-button
  35. >
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. </div>
  40. <div class="login-shadow-top"></div>
  41. <div class="login-shadow-bottom"></div>
  42. </div>
  43. </template>
  44. <script>
  45. import { password } from "@/plugins/formRules";
  46. import { login } from "../api";
  47. import { AES } from "@/plugins/crypto";
  48. export default {
  49. name: "login",
  50. data() {
  51. return {
  52. loginModel: {
  53. loginName: "",
  54. password: ""
  55. },
  56. loginRules: {
  57. loginName: [
  58. {
  59. required: true,
  60. message: "请输入用户名",
  61. trigger: "change"
  62. }
  63. ],
  64. password
  65. },
  66. roles: [],
  67. isSubmit: false
  68. };
  69. },
  70. mounted() {
  71. this.$ls.clear();
  72. },
  73. methods: {
  74. async submit(name) {
  75. const valid = await this.$refs[name].validate().catch(() => {});
  76. if (!valid) return;
  77. if (this.isSubmit) return;
  78. this.isSubmit = true;
  79. const data = await login({
  80. loginName: this.loginModel.loginName,
  81. password: AES(this.loginModel.password)
  82. }).catch(() => {});
  83. this.isSubmit = false;
  84. if (!data) return;
  85. data.account.roleCode = data.roles.map(item => item.roleCode).join();
  86. this.$ls.set("token", data.token, this.GLOBAL.authTimeout);
  87. this.$ls.set("schoolId", data.account.schoolId, this.GLOBAL.authTimeout);
  88. this.$ls.set("user", data.account, this.GLOBAL.authTimeout);
  89. this.$store.commit("setUser", data.account);
  90. this.$router.push({
  91. name: "Home"
  92. });
  93. }
  94. }
  95. };
  96. </script>