index.vue 14 KB

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