No Description

index.vue 4.4KB

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