index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="login-container">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. :rules="loginRules"
  7. class="login-form"
  8. auto-complete="on"
  9. label-position="left"
  10. >
  11. <div class="title-container">
  12. <h3 class="title">Nowwa Coffee</h3>
  13. </div>
  14. <el-form-item prop="username">
  15. <span class="svg-container">
  16. <svg-icon icon-class="user" />
  17. </span>
  18. <el-input
  19. ref="username"
  20. v-model="loginForm.username"
  21. placeholder="请输入手机号"
  22. name="username"
  23. type="text"
  24. tabindex="1"
  25. auto-complete="on"
  26. />
  27. </el-form-item>
  28. <el-form-item prop="password">
  29. <span class="svg-container">
  30. <svg-icon icon-class="password" />
  31. </span>
  32. <el-input
  33. :key="passwordType"
  34. ref="password"
  35. v-model="loginForm.password"
  36. :type="passwordType"
  37. placeholder="请输入密码"
  38. name="password"
  39. tabindex="2"
  40. auto-complete="on"
  41. @keyup.enter.native="handleLogin"
  42. />
  43. <span class="show-pwd" @click="showPwd">
  44. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  45. </span>
  46. </el-form-item>
  47. <el-button
  48. :loading="loading"
  49. type="primary"
  50. style="width:100%;margin-bottom:30px;"
  51. @click.native.prevent="handleLogin"
  52. >登 录</el-button>
  53. </el-form>
  54. </div>
  55. </template>
  56. <script>
  57. // import { validUsername } from '@/utils/validate'
  58. export default {
  59. name: "Login",
  60. data() {
  61. const validateUsername = (rule, value, callback) => {
  62. // if (!validUsername(value)) {
  63. if (!value) {
  64. callback(new Error("请输入手机号"));
  65. } else {
  66. callback();
  67. }
  68. };
  69. const validatePassword = (rule, value, callback) => {
  70. if (!value || value.length < 0) {
  71. callback(new Error("请输入正确的密码"));
  72. } else {
  73. callback();
  74. }
  75. };
  76. return {
  77. loginForm: {
  78. username: "",
  79. password: "",
  80. },
  81. loginRules: {
  82. username: [
  83. { required: true, trigger: "blur", validator: validateUsername },
  84. ],
  85. password: [
  86. { required: true, trigger: "blur", validator: validatePassword },
  87. ],
  88. },
  89. loading: false,
  90. passwordType: "password",
  91. redirect: undefined,
  92. };
  93. },
  94. watch: {
  95. $route: {
  96. handler: function (route) {
  97. this.redirect = route.query && route.query.redirect;
  98. },
  99. immediate: true,
  100. },
  101. },
  102. methods: {
  103. showPwd() {
  104. if (this.passwordType === "password") {
  105. this.passwordType = "";
  106. } else {
  107. this.passwordType = "password";
  108. }
  109. this.$nextTick(() => {
  110. this.$refs.password.focus();
  111. });
  112. },
  113. handleLogin() {
  114. this.$refs.loginForm.validate((valid) => {
  115. if (valid) {
  116. console.log(valid);
  117. this.loading = true;
  118. this.$store
  119. .dispatch("user/login", this.loginForm)
  120. .then(() => {
  121. this.$router.push({ path: this.redirect || "/" });
  122. this.loading = false;
  123. })
  124. .catch(() => {
  125. this.loading = false;
  126. });
  127. } else {
  128. console.log("error submit!!");
  129. return false;
  130. }
  131. });
  132. },
  133. },
  134. };
  135. </script>
  136. <style lang="scss">
  137. /* 修复input 背景不协调 和光标变色 */
  138. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  139. $bg: #283443;
  140. $light_gray: #fff;
  141. $cursor: #fff;
  142. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  143. .login-container .el-input input {
  144. color: $cursor;
  145. }
  146. }
  147. /* reset element-ui css */
  148. .login-container {
  149. .el-input {
  150. display: inline-block;
  151. height: 47px;
  152. width: 85%;
  153. input {
  154. background: transparent;
  155. border: 0px;
  156. -webkit-appearance: none;
  157. border-radius: 0px;
  158. padding: 12px 5px 12px 15px;
  159. color: $light_gray;
  160. height: 47px;
  161. caret-color: $cursor;
  162. &:-webkit-autofill {
  163. box-shadow: 0 0 0px 1000px $bg inset !important;
  164. -webkit-text-fill-color: $cursor !important;
  165. }
  166. }
  167. }
  168. .el-form-item {
  169. border: 1px solid rgba(255, 255, 255, 0.1);
  170. background: rgba(0, 0, 0, 0.1);
  171. border-radius: 5px;
  172. color: #454545;
  173. }
  174. }
  175. </style>
  176. <style lang="scss" scoped>
  177. $bg: #2d3a4b;
  178. $dark_gray: #889aa4;
  179. $light_gray: #eee;
  180. .login-container {
  181. min-height: 100%;
  182. width: 100%;
  183. background-color: $bg;
  184. overflow: hidden;
  185. .login-form {
  186. position: relative;
  187. width: 520px;
  188. max-width: 100%;
  189. padding: 160px 35px 0;
  190. margin: 0 auto;
  191. overflow: hidden;
  192. }
  193. .tips {
  194. font-size: 14px;
  195. color: #fff;
  196. margin-bottom: 10px;
  197. span {
  198. &:first-of-type {
  199. margin-right: 16px;
  200. }
  201. }
  202. }
  203. .svg-container {
  204. padding: 6px 5px 6px 15px;
  205. color: $dark_gray;
  206. vertical-align: middle;
  207. width: 30px;
  208. display: inline-block;
  209. }
  210. .title-container {
  211. position: relative;
  212. .title {
  213. font-size: 26px;
  214. color: $light_gray;
  215. margin: 0px auto 40px auto;
  216. text-align: center;
  217. font-weight: bold;
  218. }
  219. }
  220. .show-pwd {
  221. position: absolute;
  222. right: 10px;
  223. top: 7px;
  224. font-size: 16px;
  225. color: $dark_gray;
  226. cursor: pointer;
  227. user-select: none;
  228. }
  229. }
  230. </style>