index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
  77. if (value === '') {
  78. callback(new Error('请输入密码'))
  79. } else if (!re.test(value)) {
  80. callback(new Error('密码由8位以上数字,大小写字母,特殊字符组成'))
  81. } else {
  82. callback()
  83. }
  84. }
  85. return {
  86. loginForm: {
  87. username: '',
  88. password: ''
  89. },
  90. loginRules: {
  91. username: [
  92. { required: true, trigger: 'blur', validator: validateUsername }
  93. ],
  94. password: [
  95. { required: true, trigger: 'blur', validator: validatePassword }
  96. ]
  97. },
  98. loading: false,
  99. passwordType: 'password',
  100. redirect: undefined
  101. }
  102. },
  103. watch: {
  104. $route: {
  105. handler: function(route) {
  106. this.redirect = route.query && route.query.redirect
  107. },
  108. immediate: true
  109. }
  110. },
  111. created() {
  112. var that = this
  113. document.onkeydown = function(e) {
  114. e = window.event || e
  115. // eslint-disable-next-line eqeqeq
  116. if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
  117. that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
  118. }
  119. }
  120. },
  121. methods: {
  122. showPwd() {
  123. if (this.passwordType === 'password') {
  124. this.passwordType = ''
  125. } else {
  126. this.passwordType = 'password'
  127. }
  128. this.$nextTick(() => {
  129. this.$refs.password.focus()
  130. })
  131. },
  132. handleLogin() {
  133. this.$refs.loginForm.validate(valid => {
  134. if (valid) {
  135. this.$store.dispatch('user/login', this.loginForm) .then(() => {
  136. // const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
  137. // if (!re.test(this.loginForm.password)) {
  138. // this.$router.push('/console/Changpwd')
  139. // console.log('密码不符合要求')
  140. // }
  141. this.$router.push({ path: this.redirect || '/' })
  142. this.loading = false
  143. }).catch(() => {
  144. this.loading = false
  145. })
  146. } else {
  147. console.log('error submit!!')
  148. return false
  149. }
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss">
  156. /* 修复input 背景不协调 和光标变色 */
  157. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  158. // $bg: #283443;
  159. // $light_gray: #fff;
  160. // $cursor: #fff;
  161. // 更改
  162. $bg: #ccc;
  163. $light_gray: #ccc;
  164. $cursor: #000;
  165. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  166. .login-container .el-input input {
  167. color: $cursor;
  168. }
  169. }
  170. /* reset element-ui css */
  171. .login-container {
  172. .el-input {
  173. display: inline-block;
  174. height: 38px;
  175. width: 85%;
  176. input {
  177. background: transparent;
  178. border: 0px;
  179. -webkit-appearance: none;
  180. border-radius: 0px;
  181. padding: 5px 5px 5px 15px;
  182. color: #000;
  183. height: 38px;
  184. caret-color: $cursor;
  185. &:-webkit-autofill {
  186. box-shadow: 0 0 0px 1000px $bg inset !important;
  187. -webkit-text-fill-color: $cursor !important;
  188. }
  189. }
  190. }
  191. .el-form-item {
  192. border: 1px solid rgba(255, 255, 255, 0.1);
  193. background: rgba(0, 0, 0, 0.2);
  194. border-radius: 5px;
  195. color: #454545;
  196. .el-form-item__content {
  197. line-height: 30px;
  198. }
  199. }
  200. }
  201. </style>
  202. <style lang="scss" scoped>
  203. $bg: #2d3a4b;
  204. $dark_gray: #889aa4;
  205. $light_gray: #000;
  206. .login-container {
  207. min-height: 100%;
  208. width: 100%;
  209. position: relative;
  210. background: url("../../assets/images/login-bg.jpg") no-repeat;
  211. background-size:100%;
  212. overflow: hidden;
  213. .logo{
  214. padding: 5px;
  215. }
  216. .bujian{
  217. position: absolute;
  218. top: 0;
  219. bottom: 0;
  220. left: 0;
  221. right: 200px;
  222. margin: auto;
  223. }
  224. .login {
  225. border-radius: 5%;
  226. padding: 30px;
  227. background: #fff;
  228. width: 300px;
  229. height: 310px;
  230. position: absolute;
  231. right: 95px;
  232. margin: auto;
  233. top: 0;
  234. bottom: 0;
  235. .login-form {
  236. position: relative;
  237. width: 520px;
  238. max-width: 100%;
  239. overflow: hidden;
  240. }
  241. .tips {
  242. font-size: 14px;
  243. color: #fff;
  244. margin-bottom: 10px;
  245. span {
  246. &:first-of-type {
  247. margin-right: 16px;
  248. }
  249. }
  250. }
  251. .svg-container {
  252. padding: 6px 5px 6px 15px;
  253. color: $dark_gray;
  254. vertical-align: middle;
  255. width: 30px;
  256. display: inline-block;
  257. }
  258. .title-container {
  259. position: relative;
  260. .title {
  261. font-size: 26px;
  262. color: $light_gray;
  263. margin: 0px auto 0 auto;
  264. text-align: center;
  265. font-weight: bold;
  266. }
  267. b {
  268. text-align: center;
  269. font: 14px/2 "";
  270. }
  271. }
  272. .show-pwd {
  273. position: absolute;
  274. right: 10px;
  275. top: 7px;
  276. font-size: 16px;
  277. color: $dark_gray;
  278. cursor: pointer;
  279. user-select: none;
  280. }
  281. hr {
  282. color: #ccc;
  283. }
  284. }
  285. }
  286. </style>