index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <div class="login-container">
  3. <div class="new-login">
  4. <div class="new-login-l">
  5. <div class="imgs">
  6. <img :src="$t('auth.logo')" alt="" :lang="$i18n.locale">
  7. <div class="img-text" :lang="$i18n.locale">TMR MANAGEMENT AND MONITORING SYSTEM</div>
  8. </div>
  9. </div>
  10. <div class="new-login-r">
  11. <div class="title">{{$t('auth.signIn')}}</div>
  12. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
  13. <el-form-item prop="username">
  14. <span class="svg-container">
  15. <svg-icon icon-class="user" />
  16. </span>
  17. <el-input ref="username" v-model="loginForm.username" :placeholder="$t('auth.username')" name="username" type="text" tabindex="1" auto-complete="on" />
  18. </el-form-item>
  19. <el-form-item prop="password" class="password">
  20. <span class="svg-container">
  21. <svg-icon icon-class="password" />
  22. </span>
  23. <el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType" :placeholder="$t('auth.password')" name="password" tabindex="2" auto-complete="on" @keyup.enter.native="handleLogin" />
  24. <span class="show-pwd" @click="showPwd">
  25. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  26. </span>
  27. </el-form-item>
  28. <el-form-item class="rememberPassword">
  29. <input id="remember-password-checkbox" v-model="rememberPassword" type="checkbox" value="remember-me" @click="doRememberPassword($event)">
  30. <span for="remember-password-checkbox">
  31. {{$t('auth.rePassword')}}
  32. </span>
  33. </input>
  34. </el-form-item>
  35. </el-form>
  36. <el-button type="text" :loading="loading" class="btn" @click.native.prevent="handleLogin">{{$t('auth.userBtn')}}</el-button>
  37. </div>
  38. </div>
  39. <div style="position: absolute;bottom: 0;left: 0;right:0;color: #000;background: #fee; opacity: .7; font-size: 14px;">
  40. <p style="text-align:center;line-height:16px;">
  41. 版权所有
  42. <a href="http://www.dairyinfo.com.cn" target="_blank">上海科湃腾信息科技有限公司</a>
  43. <a style="margin-left: 20px;" href="https://beian.miit.gov.cn/" target="_blank">沪ICP备11008303号-3 </a>
  44. </p>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import { validUsername } from '@/utils/validate'
  50. import Cookies from 'js-cookie'
  51. import { getToken } from '@/utils/auth'
  52. import axios from 'axios'
  53. const md5 = require('md5')
  54. export default {
  55. name: 'Login',
  56. data() {
  57. const validateUsername = (rule, value, callback) => {
  58. if (!validUsername(value)) {
  59. callback(new Error(this.$t('auth.userTname')))
  60. } else {
  61. callback()
  62. }
  63. }
  64. const validatePassword = (rule, value, callback) => {
  65. if (!value.length) {
  66. callback(new Error(this.$t('auth.userTpassword')))
  67. } else if (value.length < 6) {
  68. callback(new Error(this.$t('auth.passwordTest')))
  69. } else {
  70. callback()
  71. }
  72. }
  73. return {
  74. loginForm: {
  75. username: '',
  76. password: ''
  77. },
  78. loginRules: {
  79. username: [
  80. {
  81. required: true,
  82. trigger: 'blur',
  83. message: this.$t('auth.usernamePlaceholder')
  84. // validator: validateUsername
  85. }
  86. ],
  87. password: [
  88. {
  89. required: true,
  90. // message: this.$t('auth.passwordPlaceholder'),
  91. trigger: 'blur',
  92. validator: validatePassword
  93. }
  94. ]
  95. },
  96. loading: false,
  97. passwordType: 'password',
  98. redirect: undefined,
  99. rememberPassword: ''
  100. }
  101. },
  102. watch: {
  103. $route: {
  104. handler: function (route) {
  105. this.redirect = route.query && route.query.redirect
  106. },
  107. immediate: true
  108. }
  109. },
  110. created() {
  111. var that = this
  112. document.onkeydown = function (e) {
  113. e = window.event || e
  114. // eslint-disable-next-line eqeqeq
  115. if (
  116. that.$route.path == '/login' &&
  117. (e.code == 'Enter' || e.code == 'Num Enter')
  118. ) {
  119. // 验证在登录界面和按得键是回车键enter
  120. that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
  121. }
  122. }
  123. },
  124. mounted: function () {
  125. // 读取cookie中的账号信息,如果有accountInfo的话,则说明该用户之前勾选了记住密码的功能,则需要自动填上账号密码
  126. this.loadAccountInfo()
  127. },
  128. methods: {
  129. showPwd() {
  130. if (this.passwordType === 'password') {
  131. this.passwordType = ''
  132. } else {
  133. this.passwordType = 'password'
  134. }
  135. this.$nextTick(() => {
  136. this.$refs.password.focus()
  137. })
  138. },
  139. handleLogin() {
  140. var obj = {
  141. username: this.loginForm.username,
  142. password: md5(this.loginForm.password)
  143. }
  144. var rememberStatus = this.rememberPassword
  145. var accountInfo = this.loginForm.username + '&' + this.loginForm.password
  146. this.$refs.loginForm.validate((valid) => {
  147. if (valid) {
  148. this.loading = true
  149. this.$store
  150. .dispatch('user/login', obj)
  151. .then(() => {
  152. // this.$store.dispatch('user/login', this.loginForm).then(() => {
  153. if (rememberStatus) {
  154. console.log('勾选了记住密码,现在开始写入cookie')
  155. Cookies.set('accountInfo', accountInfo, 1440 * 3)
  156. } else {
  157. console.log('没有勾选记住密码,现在开始删除账号cookie')
  158. Cookies.remove('accountInfo')
  159. }
  160. // 若为本地环境 则手写cookie
  161. if (window.location.href.indexOf('localhost') != -1) {
  162. Cookies.set('token', getToken(), 1440)
  163. }
  164. this.$router.push({ path: this.redirect || '/' })
  165. this.loading = false
  166. })
  167. .catch(() => {
  168. this.loading = false
  169. })
  170. } else {
  171. console.log('error submit!!')
  172. return false
  173. }
  174. })
  175. },
  176. doRememberPassword() {
  177. const rememberStatus = this.rememberPassword
  178. this.rememberPassword = !rememberStatus
  179. },
  180. loadAccountInfo: function () {
  181. const _this = this
  182. // zhaopeng&A15hOsu8YeGnCsjb
  183. const accountInfo = Cookies.get('accountInfo')
  184. // 如果cookie里没有账号信息
  185. if (Boolean(accountInfo) == false) {
  186. console.log('cookie中没有检测到账号信息!')
  187. return false
  188. } else {
  189. // 如果cookie里有账号信息
  190. console.log('cookie中检测到账号信息!现在开始预填写!')
  191. let userName = ''
  192. let passWord = ''
  193. const index = accountInfo.indexOf('&')
  194. userName = accountInfo.substring(0, index)
  195. passWord = accountInfo.substring(index + 1)
  196. // this.loginForm.username + '&' + this.loginForm.password
  197. _this.loginForm.username = userName
  198. _this.loginForm.password = passWord
  199. _this.rememberPassword = true
  200. }
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. /* 修复input 背景不协调 和光标变色 */
  207. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  208. // $bg: #283443;
  209. // $light_gray: #fff;
  210. // $cursor: #fff;
  211. // 更改
  212. // $bg: #ccc;
  213. // $light_gray: #ccc;
  214. // $cursor: #000;
  215. // @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  216. // .login-container .el-input input {
  217. // color: $cursor;
  218. // }
  219. // }
  220. // .login-container {
  221. // min-height: 232px;
  222. // .el-input {
  223. // display: inline-block;
  224. // height: 38px;
  225. // width: 80%;
  226. // input {
  227. // background: #fff;
  228. // border: 0px;
  229. // -webkit-appearance: none;
  230. // border-radius: 0px;
  231. // padding: 5px 5px 5px 15px;
  232. // color: #000;
  233. // height: 16.7%;
  234. // caret-color: $cursor;
  235. // &:-webkit-autofill {
  236. // box-shadow: 0 0 0px 1000px $bg inset !important;
  237. // -webkit-text-fill-color: $cursor !important;
  238. // }
  239. // }
  240. // }
  241. // .el-form-item {
  242. // border: 1px solid rgba(255, 255, 255, 0.1);
  243. // background: #fff;
  244. // border-radius: 5px;
  245. // color: #999;
  246. // width: 73%;
  247. // margin: 10px auto;
  248. // .el-form-item__content {
  249. // line-height: 16%;
  250. // border-bottom: 1px solid #e7e7e7;
  251. // }
  252. // }
  253. // .rememberPassword{
  254. // .el-form-item__content {
  255. // line-height:16%;
  256. // border: none;
  257. // span{padding-left: 5px;}
  258. // }
  259. // }
  260. // .password{
  261. // margin-top: 20px;margin-bottom: 15px;
  262. // }
  263. // .btn{
  264. // position: relative;
  265. // width: 520px;
  266. // max-width: 100%;
  267. // overflow: hidden;
  268. // }
  269. // .btn span{width:72%;background:#01996a;border: #01996a;border-radius: 5px;line-height: 40px; text-align: center;color:#fff; margin: 0 auto;display: block;}
  270. // }
  271. </style>
  272. /* <style>
  273. .login-container .el-input input:-webkit-autofill,
  274. textarea:-webkit-autofill,
  275. select:-webkit-autofill {
  276. -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
  277. box-shadow: 0 0 0px 1000px #fff inset !important;
  278. -webkit-text-fill-color: #000 !important;
  279. }
  280. </style> */
  281. // <style lang="scss" scoped>
  282. // $bg: #2d3a4b;
  283. // $dark_gray: #999;
  284. // $light_gray: #000;
  285. // .login-container {
  286. // min-height: 100%;
  287. // width: 100%;
  288. // height: 100%;
  289. // position: relative;
  290. // background: url("../../assets/images/nlogin-bg.png") no-repeat;
  291. // background-size:100%;
  292. // overflow: hidden;
  293. // .login {
  294. // border-radius: 5%;
  295. // padding: 30px;
  296. // background: rgba(0,0,0,0.4);
  297. // width: 380px;
  298. // height: 340px;
  299. // position: relative;
  300. // top: 50%;
  301. // left: 50%;
  302. // margin-left: -190px;
  303. // margin-top: -270px;
  304. // box-shadow:0px 0px 10px #fff;
  305. // .login-form {
  306. // margin-top: 60px;
  307. // position: relative;
  308. // width: 520px;
  309. // max-width: 100%;
  310. // overflow: hidden;
  311. // }
  312. // .tips {
  313. // font-size: 14px;
  314. // color: #fff;
  315. // margin-bottom: 10px;
  316. // span {
  317. // &:first-of-type {
  318. // margin-right: 16px;
  319. // }
  320. // }
  321. // }
  322. // .svg-container {
  323. // padding: 6px 5px 6px 15px;
  324. // color: $dark_gray;
  325. // vertical-align: middle;
  326. // width: 30px;
  327. // display: inline-block;
  328. // }
  329. // .title {
  330. // font-size: 26px;
  331. // color: $light_gray;
  332. // margin: 0px auto 0 auto;
  333. // text-align: center;
  334. // font-weight: bold;
  335. // }
  336. // b {
  337. // text-align: center;
  338. // font: 14px/2 "";
  339. // }
  340. // .show-pwd {
  341. // position: absolute;
  342. // right: 10px;
  343. // top: 7px;
  344. // font-size: 16px;
  345. // color: $dark_gray;
  346. // cursor: pointer;
  347. // user-select: none;
  348. // }
  349. // .kpt{text-align: center;color: #fff;display: inline-block;width: 100%;font:12px/18px '';}
  350. // }
  351. // }
  352. //
  353. </style>
  354. // <style lang="scss" scoped>
  355. // .login-container {
  356. // width: 100vw;
  357. // height: 100vh;
  358. // display: flex;
  359. // justify-content: center;
  360. // align-items: center;
  361. // .new-login{
  362. // width: 57%;
  363. // height: 43%;
  364. // display: flex;
  365. // .new-login-l{
  366. // flex: 1 1;
  367. // width: 50%;
  368. // background: url("../../assets/images/nlogin-bg2.png") no-repeat;
  369. // position: relative;
  370. // .new-login-l-t{
  371. // width: 34%;
  372. // height: 13%;
  373. // position: absolute;
  374. // top: 36%;
  375. // left: 32%;
  376. // right: 0;
  377. // bottom: 0;
  378. // }
  379. // .new-login-l-b{
  380. // position: absolute;
  381. // // 138,263
  382. // width: 40%;
  383. // // height: 5%;
  384. // top: 56%;
  385. // left: 30%;
  386. // // right: 0;
  387. // // bottom: 0;
  388. // }
  389. // }
  390. // .new-login-r{
  391. // flex: 1 1;
  392. // width: 50%;
  393. // background: url("../../assets/images/nlogin-bg3.png") no-repeat;
  394. // position: relative;
  395. // .title{
  396. // text-align: center;
  397. // font-size: 26px;
  398. // font-weight: 700;
  399. // color: #01996a;
  400. // padding-top: 10%;
  401. // padding-bottom: 3%;
  402. // }
  403. // .btn {position: absolute;bottom: 10%;}
  404. // }
  405. // }
  406. // }
  407. //
  408. </style>
  409. <style lang="scss" scoped>
  410. $bg: #2d3a4b;
  411. $dark_gray: #999;
  412. $light_gray: #000;
  413. $bg: #ccc;
  414. $light_gray: #ccc;
  415. $cursor: #000;
  416. .login-container {
  417. position: relative;
  418. height: 100%;
  419. width: 100%;
  420. background: url('../../assets/images/nlogin-bg1.jpg') no-repeat;
  421. background-size: cover;
  422. .new-login {
  423. width: 50%;
  424. height: 42%;
  425. position: absolute;
  426. left: 0;
  427. right: 0;
  428. bottom: 0;
  429. top: 0;
  430. margin: auto;
  431. .new-login-l {
  432. float: left;
  433. height: 100%;
  434. width: 50%;
  435. background: url('../../assets/images/nlogin-bg2.png') no-repeat;
  436. position: relative;
  437. background-size: cover;
  438. text-align: center;
  439. .imgs {
  440. position: absolute;
  441. left: 0;
  442. right: 0;
  443. bottom: 0;
  444. top: 0;
  445. margin: auto;
  446. height: 26%;
  447. width: 100%;
  448. }
  449. img {
  450. width: 50%;
  451. // height: 23%;
  452. &:lang(en) {
  453. width: 70%;
  454. }
  455. }
  456. .img-text {
  457. width: 100%;
  458. font-size: 14px;
  459. font-weight: 600;
  460. color: #019969;
  461. text-align: center;
  462. margin-top: 8px;
  463. display: none;
  464. &:lang(en) {
  465. display: block;
  466. }
  467. }
  468. }
  469. .new-login-r {
  470. background: #fff;
  471. float: left;
  472. height: 100%;
  473. width: 50%;
  474. position: relative;
  475. .title {
  476. margin-top: 10%;
  477. font-size: 20px;
  478. font-weight: 600;
  479. color: #019969;
  480. text-align: center;
  481. }
  482. .login-form {
  483. position: relative;
  484. width: 520px;
  485. overflow: hidden;
  486. height: 48%;
  487. width: 100%;
  488. .svg-container {
  489. padding: 6px 5px 6px 15px;
  490. color: $dark_gray;
  491. vertical-align: middle;
  492. width: 30px;
  493. display: inline-block;
  494. }
  495. .el-input {
  496. display: inline-block;
  497. width: 80%;
  498. }
  499. }
  500. .el-form-item {
  501. border: none;
  502. background: #fff;
  503. border-radius: 5px;
  504. color: #999;
  505. width: 73%;
  506. margin: 10px auto;
  507. height: 30%;
  508. /deep/.el-form-item__content {
  509. line-height: 16%;
  510. border-bottom: 1px solid #e7e7e7;
  511. }
  512. .el-form-item__content .el-input {
  513. /deep/.el-input__inner {
  514. border: none !important;
  515. }
  516. }
  517. }
  518. .rememberPassword {
  519. /deep/.el-form-item__content {
  520. line-height: 16%;
  521. border: none;
  522. padding-bottom: 10px;
  523. span {
  524. padding-left: 5px;
  525. }
  526. }
  527. }
  528. .password {
  529. margin-top: 10px;
  530. margin-bottom: 20px;
  531. }
  532. .btn {
  533. position: absolute;
  534. overflow: hidden;
  535. width: 75%;
  536. left: 0;
  537. right: 0;
  538. bottom: 10%;
  539. margin: 0 auto;
  540. /deep/span {
  541. background: #01996a;
  542. border: #01996a;
  543. border-radius: 5px;
  544. line-height: 40px;
  545. text-align: center;
  546. color: #fff;
  547. display: block;
  548. }
  549. }
  550. }
  551. }
  552. }
  553. </style>