index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div id="userLayout">
  3. <div class="login_panle">
  4. <div class="login_panle_form">
  5. <div class="login_panle_form_title">
  6. <img class="login_panle_form_title_logo" :src="$GIN_VUE_ADMIN.appLogo" alt=""><p class="login_panle_form_title_p">{{$GIN_VUE_ADMIN.appName}}</p>
  7. </div>
  8. <el-form
  9. ref="loginForm"
  10. :model="loginForm"
  11. :rules="rules"
  12. @keyup.enter.native="submitForm"
  13. >
  14. <el-form-item prop="username">
  15. <el-input v-model="loginForm.username" placeholder="请输入用户名">
  16. <i slot="suffix" class="el-input__icon el-icon-user" />
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item prop="password">
  20. <el-input
  21. v-model="loginForm.password"
  22. :type="lock === 'lock' ? 'password' : 'text'"
  23. placeholder="请输入密码"
  24. >
  25. <i
  26. slot="suffix"
  27. :class="'el-input__icon el-icon-' + lock"
  28. @click="changeLock"
  29. />
  30. </el-input>
  31. </el-form-item>
  32. <el-form-item style="position: relative">
  33. <el-input
  34. v-model="loginForm.captcha"
  35. name="logVerify"
  36. placeholder="请输入验证码"
  37. style="width: 60%"
  38. />
  39. <div class="vPic">
  40. <img
  41. v-if="picPath"
  42. :src="picPath"
  43. width="100%"
  44. height="100%"
  45. alt="请输入验证码"
  46. @click="loginVerify()"
  47. >
  48. </div>
  49. </el-form-item>
  50. <el-form-item>
  51. <el-button
  52. type="primary"
  53. style="width: 100%"
  54. @click="submitForm"
  55. >登 录</el-button>
  56. </el-form-item>
  57. </el-form>
  58. </div>
  59. <div class="login_panle_right" />
  60. <div class="login_panle_foot">
  61. <div class="links">
  62. <a href="http://doc.henrongyi.top/"><img src="@/assets/docs.png" class="link-icon"></a>
  63. <a href="https://www.yuque.com/flipped-aurora/"><img src="@/assets/yuque.png" class="link-icon"></a>
  64. <a href="https://github.com/flipped-aurora/gin-vue-admin"><img src="@/assets/github.png" class="link-icon"></a>
  65. <a href="https://space.bilibili.com/322210472"><img src="@/assets/video.png" class="link-icon"></a>
  66. </div>
  67. <div class="copyright">Copyright &copy; {{ curYear }} 💖 flipped-aurora</div>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. import { mapActions } from 'vuex'
  74. import { captcha } from '@/api/user'
  75. export default {
  76. name: 'Login',
  77. data() {
  78. const checkUsername = (rule, value, callback) => {
  79. if (value.length < 5) {
  80. return callback(new Error('请输入正确的用户名'))
  81. } else {
  82. callback()
  83. }
  84. }
  85. const checkPassword = (rule, value, callback) => {
  86. if (value.length < 6) {
  87. return callback(new Error('请输入正确的密码'))
  88. } else {
  89. callback()
  90. }
  91. }
  92. return {
  93. curYear: 0,
  94. lock: 'lock',
  95. loginForm: {
  96. username: 'admin',
  97. password: '123456',
  98. captcha: '',
  99. captchaId: ''
  100. },
  101. rules: {
  102. username: [{ validator: checkUsername, trigger: 'blur' }],
  103. password: [{ validator: checkPassword, trigger: 'blur' }]
  104. },
  105. logVerify: '',
  106. picPath: ''
  107. }
  108. },
  109. created() {
  110. this.loginVerify()
  111. this.curYear = new Date().getFullYear()
  112. },
  113. methods: {
  114. ...mapActions('user', ['LoginIn']),
  115. async login() {
  116. return await this.LoginIn(this.loginForm)
  117. },
  118. async submitForm() {
  119. this.$refs.loginForm.validate(async(v) => {
  120. if (v) {
  121. const flag = await this.login()
  122. if (!flag) {
  123. this.loginVerify()
  124. }
  125. } else {
  126. this.$message({
  127. type: 'error',
  128. message: '请正确填写登录信息',
  129. showClose: true
  130. })
  131. this.loginVerify()
  132. return false
  133. }
  134. })
  135. },
  136. changeLock() {
  137. this.lock = this.lock === 'lock' ? 'unlock' : 'lock'
  138. },
  139. loginVerify() {
  140. captcha({}).then((ele) => {
  141. this.picPath = ele.data.picPath
  142. this.loginForm.captchaId = ele.data.captchaId
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. @import "@/style/newLogin.scss";
  150. </style>