081b192aac515ef359efd665596617fb049fa298.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="login-container">
  3. <img src="@/assets/images/logo.png" alt class="logo">
  4. <img src="@/assets/images/login-bujian.png" alt="" class="bujian">
  5. <div class="login">
  6. <div class="logo" />
  7. <el-form
  8. ref="loginForm"
  9. :model="loginForm"
  10. :rules="loginRules"
  11. class="login-form"
  12. auto-complete="on"
  13. label-position="left"
  14. >
  15. <div class="title-container">
  16. <h3 class="title">设备管理系统</h3>
  17. <b>Equipment Management System</b>
  18. <hr>
  19. </div>
  20. <el-form-item prop="username">
  21. <span class="svg-container">
  22. <svg-icon icon-class="user" />
  23. </span>
  24. <el-input
  25. ref="username"
  26. v-model="loginForm.username"
  27. placeholder="Username"
  28. name="username"
  29. type="text"
  30. tabindex="1"
  31. auto-complete="on"
  32. />
  33. </el-form-item>
  34. <el-form-item prop="password">
  35. <span class="svg-container">
  36. <svg-icon icon-class="password" />
  37. </span>
  38. <el-input
  39. :key="passwordType"
  40. ref="password"
  41. v-model="loginForm.password"
  42. :type="passwordType"
  43. placeholder="Password"
  44. name="password"
  45. tabindex="2"
  46. auto-complete="on"
  47. @keyup.enter.native="handleLogin"
  48. />
  49. <span class="show-pwd" @click="showPwd">
  50. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  51. </span>
  52. </el-form-item>
  53. <el-button
  54. :loading="loading"
  55. type="primary"
  56. style="width:100%;margin-bottom:30px;background:#009688;"
  57. @click.native.prevent="handleLogin"
  58. >登录</el-button>
  59. </el-form>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import { validUsername } from '@/utils/validate'
  65. export default {
  66. name: 'Login',
  67. data() {
  68. const validateUsername = (rule, value, callback) => {
  69. if (!validUsername(value)) {
  70. callback(new Error('请输入正确的用户名'))
  71. } else {
  72. callback()
  73. }
  74. }
  75. const validatePassword = (rule, value, callback) => {
  76. if (value.length < 6) {
  77. callback(new Error('密码不能少于6个字符'))
  78. } else {
  79. callback()
  80. }
  81. }
  82. return {
  83. loginForm: {
  84. username: '',
  85. password: ''
  86. },
  87. loginRules: {
  88. username: [
  89. { required: true, trigger: 'blur', validator: validateUsername }
  90. ],
  91. password: [
  92. { required: true, trigger: 'blur', validator: validatePassword }
  93. ]
  94. },
  95. loading: false,
  96. passwordType: 'password',
  97. redirect: undefined
  98. }
  99. },
  100. watch: {
  101. $route: {
  102. handler: function(route) {
  103. this.redirect = route.query && route.query.redirect
  104. },
  105. immediate: true
  106. }
  107. },
  108. created() {
  109. var that = this
  110. document.onkeydown = function(e) {
  111. e = window.event || e
  112. // eslint-disable-next-line eqeqeq
  113. if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
  114. that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
  115. }
  116. }
  117. },
  118. methods: {
  119. showPwd() {
  120. if (this.passwordType === 'password') {
  121. this.passwordType = ''
  122. } else {
  123. this.passwordType = 'password'
  124. }
  125. this.$nextTick(() => {
  126. this.$refs.password.focus()
  127. })
  128. },
  129. handleLogin() {
  130. this.$refs.loginForm.validate(valid => {
  131. if (valid) {
  132. this.loading = true
  133. this.$store
  134. .dispatch('user/login', this.loginForm)
  135. .then(() => {
  136. this.$router.push({ path: this.redirect || '/' })
  137. this.loading = false
  138. })
  139. .catch(() => {
  140. this.loading = false
  141. })
  142. } else {
  143. console.log('error submit!!')
  144. return false
  145. }
  146. })
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss">
  152. /* 修复input 背景不协调 和光标变色 */
  153. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  154. // $bg: #283443;
  155. // $light_gray: #fff;
  156. // $cursor: #fff;
  157. // 更改
  158. $bg: #ccc;
  159. $light_gray: #ccc;
  160. $cursor: #000;
  161. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  162. .login-container .el-input input {
  163. color: $cursor;
  164. }
  165. }
  166. /* reset element-ui css */
  167. .login-container {
  168. .el-input {
  169. display: inline-block;
  170. height: 38px;
  171. width: 85%;
  172. input {
  173. background: transparent;
  174. border: 0px;
  175. -webkit-appearance: none;
  176. border-radius: 0px;
  177. padding: 5px 5px 5px 15px;
  178. color: #000;
  179. height: 38px;
  180. caret-color: $cursor;
  181. &:-webkit-autofill {
  182. box-shadow: 0 0 0px 1000px $bg inset !important;
  183. -webkit-text-fill-color: $cursor !important;
  184. }
  185. }
  186. }
  187. .el-form-item {
  188. border: 1px solid rgba(255, 255, 255, 0.1);
  189. background: rgba(0, 0, 0, 0.2);
  190. border-radius: 5px;
  191. color: #454545;
  192. .el-form-item__content {
  193. line-height: 30px;
  194. }
  195. }
  196. }
  197. </style>
  198. <style lang="scss" scoped>
  199. $bg: #2d3a4b;
  200. $dark_gray: #889aa4;
  201. $light_gray: #000;
  202. .login-container {
  203. min-height: 100%;
  204. width: 100%;
  205. position: relative;
  206. background: url("../../assets/images/login-bg.jpg") no-repeat;
  207. background-size:100%;
  208. overflow: hidden;
  209. .logo{
  210. padding: 5px;
  211. }
  212. .bujian{
  213. position: absolute;
  214. top: 0;
  215. bottom: 0;
  216. left: 0;
  217. right: 200px;
  218. margin: auto;
  219. }
  220. .login {
  221. border-radius: 5%;
  222. padding: 30px;
  223. background: #fff;
  224. width: 300px;
  225. height: 310px;
  226. position: absolute;
  227. right: 95px;
  228. margin: auto;
  229. top: 0;
  230. bottom: 0;
  231. .login-form {
  232. position: relative;
  233. width: 520px;
  234. max-width: 100%;
  235. overflow: hidden;
  236. }
  237. .tips {
  238. font-size: 14px;
  239. color: #fff;
  240. margin-bottom: 10px;
  241. span {
  242. &:first-of-type {
  243. margin-right: 16px;
  244. }
  245. }
  246. }
  247. .svg-container {
  248. padding: 6px 5px 6px 15px;
  249. color: $dark_gray;
  250. vertical-align: middle;
  251. width: 30px;
  252. display: inline-block;
  253. }
  254. .title-container {
  255. position: relative;
  256. .title {
  257. font-size: 26px;
  258. color: $light_gray;
  259. margin: 0px auto 0 auto;
  260. text-align: center;
  261. font-weight: bold;
  262. }
  263. b {
  264. text-align: center;
  265. font: 14px/2 "";
  266. }
  267. }
  268. .show-pwd {
  269. position: absolute;
  270. right: 10px;
  271. top: 7px;
  272. font-size: 16px;
  273. color: $dark_gray;
  274. cursor: pointer;
  275. user-select: none;
  276. }
  277. hr {
  278. color: #ccc;
  279. }
  280. }
  281. }
  282. </style>