index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="login-container">
  3. <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px"
  4. class="card-box login-form">
  5. <h3 class="title">vue-element-admin</h3>
  6. <el-form-item prop="username">
  7. <span class="svg-container svg-container_login">
  8. <svg-icon icon-class="user" />
  9. </span>
  10. <el-input name="username" type="text" v-model="loginForm.username" autoComplete="on" placeholder="username" />
  11. </el-form-item>
  12. <el-form-item prop="password">
  13. <span class="svg-container">
  14. <svg-icon icon-class="password"></svg-icon>
  15. </span>
  16. <el-input name="password" :type="pwdType" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
  17. placeholder="password"></el-input>
  18. <span class="show-pwd" @click="showPwd"><svg-icon icon-class="eye" /></span>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
  22. Sign in
  23. </el-button>
  24. </el-form-item>
  25. <div class="tips">
  26. <span style="margin-right:20px;">username: admin</span>
  27. <span> password: admin</span>
  28. </div>
  29. </el-form>
  30. </div>
  31. </template>
  32. <script>
  33. import { isvalidUsername } from '@/utils/validate'
  34. export default {
  35. name: 'login',
  36. data() {
  37. const validateUsername = (rule, value, callback) => {
  38. if (!isvalidUsername(value)) {
  39. callback(new Error('请输入正确的用户名'))
  40. } else {
  41. callback()
  42. }
  43. }
  44. const validatePass = (rule, value, callback) => {
  45. if (value.length < 5) {
  46. callback(new Error('密码不能小于5位'))
  47. } else {
  48. callback()
  49. }
  50. }
  51. return {
  52. loginForm: {
  53. username: 'admin',
  54. password: 'admin'
  55. },
  56. loginRules: {
  57. username: [{ required: true, trigger: 'blur', validator: validateUsername }],
  58. password: [{ required: true, trigger: 'blur', validator: validatePass }]
  59. },
  60. loading: false,
  61. pwdType: 'password'
  62. }
  63. },
  64. methods: {
  65. showPwd() {
  66. if (this.pwdType === 'password') {
  67. this.pwdType = ''
  68. } else {
  69. this.pwdType = 'password'
  70. }
  71. },
  72. handleLogin() {
  73. this.$refs.loginForm.validate(valid => {
  74. if (valid) {
  75. this.loading = true
  76. this.$store.dispatch('Login', this.loginForm).then(() => {
  77. this.loading = false
  78. this.$router.push({ path: '/' })
  79. }).catch(() => {
  80. this.loading = false
  81. })
  82. } else {
  83. console.log('error submit!!')
  84. return false
  85. }
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style rel="stylesheet/scss" lang="scss">
  92. @import "src/styles/mixin.scss";
  93. $bg:#2d3a4b;
  94. $dark_gray:#889aa4;
  95. $light_gray:#eee;
  96. .login-container {
  97. @include relative;
  98. height: 100vh;
  99. background-color: $bg;
  100. input:-webkit-autofill {
  101. -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
  102. -webkit-text-fill-color: #fff !important;
  103. }
  104. input {
  105. background: transparent;
  106. border: 0px;
  107. -webkit-appearance: none;
  108. border-radius: 0px;
  109. padding: 12px 5px 12px 15px;
  110. color: $light_gray;
  111. height: 47px;
  112. }
  113. .el-input {
  114. display: inline-block;
  115. height: 47px;
  116. width: 85%;
  117. }
  118. .tips {
  119. font-size: 14px;
  120. color: #fff;
  121. margin-bottom: 10px;
  122. }
  123. .svg-container {
  124. padding: 6px 5px 6px 15px;
  125. color: $dark_gray;
  126. vertical-align: middle;
  127. width: 30px;
  128. display: inline-block;
  129. &_login {
  130. font-size: 20px;
  131. }
  132. }
  133. .title {
  134. font-size: 26px;
  135. font-weight: 400;
  136. color: $light_gray;
  137. margin: 0px auto 40px auto;
  138. text-align: center;
  139. font-weight: bold;
  140. }
  141. .login-form {
  142. position: absolute;
  143. left: 0;
  144. right: 0;
  145. width: 400px;
  146. padding: 35px 35px 15px 35px;
  147. margin: 120px auto;
  148. }
  149. .el-form-item {
  150. border: 1px solid rgba(255, 255, 255, 0.1);
  151. background: rgba(0, 0, 0, 0.1);
  152. border-radius: 5px;
  153. color: #454545;
  154. }
  155. .show-pwd {
  156. position: absolute;
  157. right: 10px;
  158. top: 7px;
  159. font-size: 16px;
  160. color: $dark_gray;
  161. cursor: pointer;
  162. user-select:none;
  163. }
  164. .thirdparty-button{
  165. position: absolute;
  166. right: 35px;
  167. bottom: 28px;
  168. }
  169. }
  170. </style>