index.vue 14 KB

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