index.vue 7.7 KB

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