index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="page-login">
  3. <div class="box">
  4. <img class="logo" src="../../static/images/logo.png" alt="" />
  5. <p class="desc">COOL ADMIN是一款快速开发后台权限管理系统</p>
  6. <el-form ref="form" class="form" size="medium" :disabled="saving">
  7. <el-form-item label="用户名">
  8. <el-input
  9. placeholder="请输入用户名"
  10. v-model="form.username"
  11. maxlength="20"
  12. auto-complete="off"
  13. ></el-input>
  14. </el-form-item>
  15. <el-form-item label="密码">
  16. <el-input
  17. type="password"
  18. placeholder="请输入密码"
  19. v-model="form.password"
  20. maxlength="20"
  21. auto-complete="off"
  22. ></el-input>
  23. </el-form-item>
  24. <el-form-item label="验证码" class="captcha">
  25. <el-input
  26. placeholder="请输入图片验证码"
  27. maxlength="4"
  28. v-model="form.verifyCode"
  29. auto-complete="off"
  30. @keyup.enter.native="next"
  31. ></el-input>
  32. <captcha
  33. ref="captcha"
  34. class="value"
  35. v-model="form.captchaId"
  36. @change="captchaChange"
  37. ></captcha>
  38. </el-form-item>
  39. </el-form>
  40. <el-button round size="mini" class="submit-btn" @click="next" :loading="saving"
  41. >登录</el-button
  42. >
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import Captcha from "./components/captcha";
  48. export default {
  49. components: {
  50. Captcha
  51. },
  52. data() {
  53. return {
  54. form: {
  55. username: "admin",
  56. password: "123456",
  57. captchaId: "",
  58. verifyCode: ""
  59. },
  60. saving: false
  61. };
  62. },
  63. methods: {
  64. captchaChange() {
  65. this.form.verifyCode = "";
  66. },
  67. async next() {
  68. const { username, password, verifyCode } = this.form;
  69. if (!username) {
  70. return this.$message.warning("用户名不能为空");
  71. }
  72. if (!password) {
  73. return this.$message.warning("密码不能为空");
  74. }
  75. if (!verifyCode) {
  76. return this.$message.warning("图片验证码不能为空");
  77. }
  78. this.saving = true;
  79. try {
  80. // 登录
  81. await this.$store.dispatch("userLogin", this.form);
  82. // 用户信息
  83. await this.$store.dispatch("userInfo");
  84. // 权限菜单
  85. let [first] = await this.$store.dispatch("permMenu");
  86. if (!first) {
  87. this.$message.error("该账号没有权限");
  88. } else {
  89. this.$router.push("/");
  90. }
  91. } catch (err) {
  92. this.$message.error(err);
  93. this.$refs.captcha.refresh();
  94. }
  95. this.saving = false;
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .page-login {
  102. height: 100vh;
  103. width: 100vw;
  104. position: relative;
  105. background-color: $color-main;
  106. .box {
  107. display: flex;
  108. flex-direction: column;
  109. justify-content: center;
  110. align-items: center;
  111. height: 500px;
  112. width: 500px;
  113. position: absolute;
  114. left: calc(50% - 250px);
  115. top: calc(50% - 250px);
  116. .logo {
  117. height: 50px;
  118. margin-bottom: 20px;
  119. }
  120. .desc {
  121. color: #ccc;
  122. font-size: 12px;
  123. margin-bottom: 60px;
  124. letter-spacing: 1px;
  125. }
  126. /deep/.el-form {
  127. width: 300px;
  128. border-radius: 3px;
  129. .el-form-item {
  130. margin-bottom: 20px;
  131. &__label {
  132. color: #ccc;
  133. }
  134. }
  135. .el-input {
  136. .el-input__inner {
  137. border: 0;
  138. border-bottom: 0.5px solid #999;
  139. border-radius: 0;
  140. padding: 0;
  141. background-color: transparent;
  142. color: #ccc;
  143. transition: border-color 0.3s;
  144. position: relative;
  145. &:focus {
  146. border-color: #fff;
  147. color: #fff;
  148. }
  149. &:-webkit-autofill {
  150. -webkit-text-fill-color: #fff !important;
  151. -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
  152. transition: background-color 50000s ease-in-out 0s;
  153. }
  154. }
  155. }
  156. .captcha {
  157. position: relative;
  158. .value {
  159. position: absolute;
  160. bottom: 1px;
  161. right: 0;
  162. }
  163. }
  164. }
  165. .submit-btn {
  166. margin-top: 40px;
  167. border-radius: 30px;
  168. padding: 10px 40px;
  169. color: #000;
  170. }
  171. }
  172. }
  173. </style>