index.vue 16 KB

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