index.vue 5.6 KB

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