index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="login-container">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. :rules="loginRules"
  7. class="login-form"
  8. autocomplete="on"
  9. label-position="left"
  10. >
  11. <div class="title-container">
  12. <h3 class="title"><img src="/logo.svg" alt=""><span>认证通</span></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. autocomplete="on"
  26. @input="handleInput"
  27. />
  28. </el-form-item>
  29. <el-tooltip v-model="capsTooltip" content="大写已开启" placement="right" manual>
  30. <el-form-item prop="password">
  31. <span class="svg-container">
  32. <svg-icon icon-class="password" />
  33. </span>
  34. <el-input
  35. :key="passwordType"
  36. ref="password"
  37. v-model="loginForm.password"
  38. :type="passwordType"
  39. placeholder="请输入密码"
  40. name="password"
  41. tabindex="2"
  42. autocomplete="on"
  43. @keyup.native="checkCapslock"
  44. @blur="capsTooltip = false"
  45. @keyup.enter.native="handleLogin"
  46. />
  47. <span class="show-pwd" @click="showPwd">
  48. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  49. </span>
  50. </el-form-item>
  51. </el-tooltip>
  52. <el-button
  53. :loading="loading"
  54. type="primary"
  55. style="width:100%;margin-bottom:44px;"
  56. @click.native.prevent="handleLogin"
  57. >登录</el-button>
  58. </el-form>
  59. </div>
  60. </template>
  61. <script>
  62. import { setToken, setUserInfo } from '@/utils/auth'
  63. export default {
  64. name: 'Login',
  65. data() {
  66. return {
  67. loginForm: {
  68. username: '',
  69. password: ''
  70. },
  71. loginRules: {
  72. username: [{ required: true, trigger: 'blur', message: '请输入登录账号' }],
  73. password: [{ required: true, trigger: 'blur', message: '请输入登录密码' }]
  74. },
  75. passwordType: 'password',
  76. capsTooltip: false,
  77. loading: false,
  78. redirect: undefined,
  79. otherQuery: {}
  80. }
  81. },
  82. mounted() {
  83. if (this.loginForm.username === '') {
  84. this.$refs.username.focus()
  85. } else if (this.loginForm.password === '') {
  86. this.$refs.password.focus()
  87. }
  88. },
  89. methods: {
  90. checkCapslock(e) {
  91. const { key } = e
  92. this.capsTooltip = key && key.length === 1 && key >= 'A' && key <= 'Z'
  93. },
  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) return
  107. this.loading = true
  108. this.$store.dispatch('user/login', this.loginForm).then(res => {
  109. // 保存token及用户信息
  110. setToken(res.data.token)
  111. setUserInfo(res.data)
  112. this.$store.commit('tagsView/CLEAR_ALL_VIEW')
  113. this.$router.replace({ path: '/login/redirect' })
  114. }).finally(() => {
  115. this.loading = false
  116. })
  117. })
  118. },
  119. handleInput() {
  120. this.loginForm.username = this.loginForm.username.replace(/[^\w\.\/]/gi, '')
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. /* 修复input 背景不协调 和光标变色 */
  127. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  128. $bg: #283443;
  129. $light_gray: #fff;
  130. $cursor: #fff;
  131. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  132. .login-container .el-input input {
  133. color: $cursor;
  134. }
  135. }
  136. /* reset element-ui css */
  137. .login-container {
  138. .el-input {
  139. display: inline-block;
  140. height: 47px;
  141. width: 85%;
  142. input {
  143. background: transparent;
  144. border: 0px;
  145. -webkit-appearance: none;
  146. border-radius: 0px;
  147. padding: 12px 5px 12px 15px;
  148. color: $light_gray;
  149. height: 47px;
  150. caret-color: $cursor;
  151. &:-webkit-autofill {
  152. box-shadow: 0 0 0px 1000px $bg inset !important;
  153. -webkit-text-fill-color: $cursor !important;
  154. }
  155. }
  156. }
  157. .el-form-item {
  158. border: 1px solid rgba(255, 255, 255, 0.1);
  159. background: rgba(0, 0, 0, 0.1);
  160. border-radius: 5px;
  161. color: #454545;
  162. }
  163. }
  164. </style>
  165. <style lang="scss" scoped>
  166. $bg: #2d3a4b;
  167. $dark_gray: #889aa4;
  168. $light_gray: #eee;
  169. .login-container {
  170. min-height: 100%;
  171. width: 100%;
  172. background-color: $bg;
  173. overflow: hidden;
  174. .login-form {
  175. position: relative;
  176. width: 520px;
  177. max-width: 100%;
  178. padding: 160px 35px 0;
  179. margin: 0 auto;
  180. overflow: hidden;
  181. }
  182. .tips {
  183. font-size: 14px;
  184. color: #fff;
  185. margin-bottom: 10px;
  186. span {
  187. &:first-of-type {
  188. margin-right: 16px;
  189. }
  190. }
  191. }
  192. .svg-container {
  193. padding: 6px 5px 6px 15px;
  194. color: $dark_gray;
  195. vertical-align: middle;
  196. width: 30px;
  197. display: inline-block;
  198. }
  199. .title-container {
  200. position: relative;
  201. .title {
  202. font-size: 36px;
  203. color: $light_gray;
  204. margin: 0px auto 40px auto;
  205. text-align: center;
  206. font-weight: bold;
  207. span{
  208. vertical-align: middle;
  209. margin-left: 16px;
  210. }
  211. img{
  212. width: 50px;
  213. height: 50px;
  214. vertical-align: middle;
  215. }
  216. }
  217. }
  218. .show-pwd {
  219. position: absolute;
  220. right: 10px;
  221. top: 7px;
  222. font-size: 16px;
  223. color: $dark_gray;
  224. cursor: pointer;
  225. user-select: none;
  226. }
  227. .thirdparty-button {
  228. position: absolute;
  229. right: 0;
  230. bottom: 6px;
  231. }
  232. @media only screen and (max-width: 470px) {
  233. .thirdparty-button {
  234. display: none;
  235. }
  236. }
  237. }
  238. </style>