index.vue 4.5 KB

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