index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. <icon-svg icon-class="yonghuming" />
  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. <icon-svg icon-class="mima"></icon-svg>
  15. </span>
  16. <el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password" autoComplete="on"
  17. placeholder="password"></el-input>
  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. }
  61. },
  62. methods: {
  63. handleLogin() {
  64. this.$refs.loginForm.validate(valid => {
  65. if (valid) {
  66. this.loading = true
  67. this.$store.dispatch('Login', this.loginForm).then(() => {
  68. this.loading = false
  69. this.$router.push({ path: '/' })
  70. }).catch(() => {
  71. this.loading = false
  72. })
  73. } else {
  74. console.log('error submit!!')
  75. return false
  76. }
  77. })
  78. }
  79. }
  80. }
  81. </script>
  82. <style rel="stylesheet/scss" lang="scss">
  83. @import "src/styles/mixin.scss";
  84. $bg:#2d3a4b;
  85. $dark_gray:#889aa4;
  86. $light_gray:#eee;
  87. .login-container {
  88. @include relative;
  89. height: 100vh;
  90. background-color: $bg;
  91. input:-webkit-autofill {
  92. -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
  93. -webkit-text-fill-color: #fff !important;
  94. }
  95. input {
  96. background: transparent;
  97. border: 0px;
  98. -webkit-appearance: none;
  99. border-radius: 0px;
  100. padding: 12px 5px 12px 15px;
  101. color: $light_gray;
  102. height: 47px;
  103. }
  104. .el-input {
  105. display: inline-block;
  106. height: 47px;
  107. width: 85%;
  108. }
  109. .tips {
  110. font-size: 14px;
  111. color: #fff;
  112. margin-bottom: 10px;
  113. }
  114. .svg-container {
  115. padding: 6px 5px 6px 15px;
  116. color: $dark_gray;
  117. vertical-align: middle;
  118. width: 30px;
  119. display: inline-block;
  120. &_login {
  121. font-size: 20px;
  122. }
  123. }
  124. .title {
  125. font-size: 26px;
  126. font-weight: 400;
  127. color: $light_gray;
  128. margin: 0px auto 40px auto;
  129. text-align: center;
  130. font-weight: bold;
  131. }
  132. .login-form {
  133. position: absolute;
  134. left: 0;
  135. right: 0;
  136. width: 400px;
  137. padding: 35px 35px 15px 35px;
  138. margin: 120px auto;
  139. }
  140. .el-form-item {
  141. border: 1px solid rgba(255, 255, 255, 0.1);
  142. background: rgba(0, 0, 0, 0.1);
  143. border-radius: 5px;
  144. color: #454545;
  145. }
  146. .show-pwd {
  147. position: absolute;
  148. right: 10px;
  149. top: 7px;
  150. font-size: 16px;
  151. color: $dark_gray;
  152. cursor: pointer;
  153. }
  154. .thirdparty-button{
  155. position: absolute;
  156. right: 35px;
  157. bottom: 28px;
  158. }
  159. }
  160. </style>