index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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">用户登录</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="用户名" 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="密码" 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. 记住密码
  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. const md5 = require("md5")
  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 obj = {
  121. username: this.loginForm.username,
  122. password: md5(this.loginForm.password)
  123. }
  124. var rememberStatus = this.rememberPassword
  125. var accountInfo = this.loginForm.username + '&' + this.loginForm.password
  126. this.$refs.loginForm.validate(valid => {
  127. if (valid) {
  128. this.loading = true
  129. this.$store.dispatch('user/login', obj).then(() => {
  130. // this.$store.dispatch('user/login', this.loginForm).then(() => {
  131. if (rememberStatus) {
  132. console.log('勾选了记住密码,现在开始写入cookie')
  133. Cookies.set('accountInfo', accountInfo, 1440 * 3)
  134. } else {
  135. console.log('没有勾选记住密码,现在开始删除账号cookie')
  136. Cookies.remove('accountInfo')
  137. }
  138. // 若为本地环境 则手写cookie
  139. if (window.location.href.indexOf('localhost') != -1) {
  140. Cookies.set('token', getToken(), 1440)
  141. }
  142. this.$router.push({ path: this.redirect || '/' })
  143. this.loading = false
  144. })
  145. .catch(() => {
  146. this.loading = false
  147. })
  148. } else {
  149. console.log('error submit!!')
  150. return false
  151. }
  152. })
  153. },
  154. doRememberPassword() {
  155. const rememberStatus = this.rememberPassword
  156. this.rememberPassword = !rememberStatus
  157. },
  158. loadAccountInfo: function() {
  159. const _this = this
  160. // zhaopeng&A15hOsu8YeGnCsjb
  161. const accountInfo = Cookies.get('accountInfo')
  162. // 如果cookie里没有账号信息
  163. if (Boolean(accountInfo) == false) {
  164. console.log('cookie中没有检测到账号信息!')
  165. return false
  166. } else {
  167. // 如果cookie里有账号信息
  168. console.log('cookie中检测到账号信息!现在开始预填写!')
  169. let userName = ''
  170. let passWord = ''
  171. const index = accountInfo.indexOf('&')
  172. userName = accountInfo.substring(0, index)
  173. passWord = accountInfo.substring(index + 1)
  174. // this.loginForm.username + '&' + this.loginForm.password
  175. _this.loginForm.username = userName
  176. _this.loginForm.password = passWord
  177. _this.rememberPassword = true
  178. }
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. /* 修复input 背景不协调 和光标变色 */
  185. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  186. // $bg: #283443;
  187. // $light_gray: #fff;
  188. // $cursor: #fff;
  189. // 更改
  190. // $bg: #ccc;
  191. // $light_gray: #ccc;
  192. // $cursor: #000;
  193. // @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  194. // .login-container .el-input input {
  195. // color: $cursor;
  196. // }
  197. // }
  198. // .login-container {
  199. // min-height: 232px;
  200. // .el-input {
  201. // display: inline-block;
  202. // height: 38px;
  203. // width: 80%;
  204. // input {
  205. // background: #fff;
  206. // border: 0px;
  207. // -webkit-appearance: none;
  208. // border-radius: 0px;
  209. // padding: 5px 5px 5px 15px;
  210. // color: #000;
  211. // height: 16.7%;
  212. // caret-color: $cursor;
  213. // &:-webkit-autofill {
  214. // box-shadow: 0 0 0px 1000px $bg inset !important;
  215. // -webkit-text-fill-color: $cursor !important;
  216. // }
  217. // }
  218. // }
  219. // .el-form-item {
  220. // border: 1px solid rgba(255, 255, 255, 0.1);
  221. // background: #fff;
  222. // border-radius: 5px;
  223. // color: #999;
  224. // width: 73%;
  225. // margin: 10px auto;
  226. // .el-form-item__content {
  227. // line-height: 16%;
  228. // border-bottom: 1px solid #e7e7e7;
  229. // }
  230. // }
  231. // .rememberPassword{
  232. // .el-form-item__content {
  233. // line-height:16%;
  234. // border: none;
  235. // span{padding-left: 5px;}
  236. // }
  237. // }
  238. // .password{
  239. // margin-top: 20px;margin-bottom: 15px;
  240. // }
  241. // .btn{
  242. // position: relative;
  243. // width: 520px;
  244. // max-width: 100%;
  245. // overflow: hidden;
  246. // }
  247. // .btn span{width:72%;background:#01996a;border: #01996a;border-radius: 5px;line-height: 40px; text-align: center;color:#fff; margin: 0 auto;display: block;}
  248. // }
  249. </style>
  250. /* <style>
  251. .login-container .el-input input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
  252. -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
  253. box-shadow: 0 0 0px 1000px #fff inset !important;
  254. -webkit-text-fill-color: #000 !important;
  255. }
  256. </style> */
  257. // <style lang="scss" scoped>
  258. // $bg: #2d3a4b;
  259. // $dark_gray: #999;
  260. // $light_gray: #000;
  261. // .login-container {
  262. // min-height: 100%;
  263. // width: 100%;
  264. // height: 100%;
  265. // position: relative;
  266. // background: url("../../assets/images/nlogin-bg.png") no-repeat;
  267. // background-size:100%;
  268. // overflow: hidden;
  269. // .login {
  270. // border-radius: 5%;
  271. // padding: 30px;
  272. // background: rgba(0,0,0,0.4);
  273. // width: 380px;
  274. // height: 340px;
  275. // position: relative;
  276. // top: 50%;
  277. // left: 50%;
  278. // margin-left: -190px;
  279. // margin-top: -270px;
  280. // box-shadow:0px 0px 10px #fff;
  281. // .login-form {
  282. // margin-top: 60px;
  283. // position: relative;
  284. // width: 520px;
  285. // max-width: 100%;
  286. // overflow: hidden;
  287. // }
  288. // .tips {
  289. // font-size: 14px;
  290. // color: #fff;
  291. // margin-bottom: 10px;
  292. // span {
  293. // &:first-of-type {
  294. // margin-right: 16px;
  295. // }
  296. // }
  297. // }
  298. // .svg-container {
  299. // padding: 6px 5px 6px 15px;
  300. // color: $dark_gray;
  301. // vertical-align: middle;
  302. // width: 30px;
  303. // display: inline-block;
  304. // }
  305. // .title {
  306. // font-size: 26px;
  307. // color: $light_gray;
  308. // margin: 0px auto 0 auto;
  309. // text-align: center;
  310. // font-weight: bold;
  311. // }
  312. // b {
  313. // text-align: center;
  314. // font: 14px/2 "";
  315. // }
  316. // .show-pwd {
  317. // position: absolute;
  318. // right: 10px;
  319. // top: 7px;
  320. // font-size: 16px;
  321. // color: $dark_gray;
  322. // cursor: pointer;
  323. // user-select: none;
  324. // }
  325. // .kpt{text-align: center;color: #fff;display: inline-block;width: 100%;font:12px/18px '';}
  326. // }
  327. // }
  328. // </style>
  329. // <style lang="scss" scoped>
  330. // .login-container {
  331. // width: 100vw;
  332. // height: 100vh;
  333. // display: flex;
  334. // justify-content: center;
  335. // align-items: center;
  336. // .new-login{
  337. // width: 57%;
  338. // height: 43%;
  339. // display: flex;
  340. // .new-login-l{
  341. // flex: 1 1;
  342. // width: 50%;
  343. // background: url("../../assets/images/nlogin-bg2.png") no-repeat;
  344. // position: relative;
  345. // .new-login-l-t{
  346. // width: 34%;
  347. // height: 13%;
  348. // position: absolute;
  349. // top: 36%;
  350. // left: 32%;
  351. // right: 0;
  352. // bottom: 0;
  353. // }
  354. // .new-login-l-b{
  355. // position: absolute;
  356. // // 138,263
  357. // width: 40%;
  358. // // height: 5%;
  359. // top: 56%;
  360. // left: 30%;
  361. // // right: 0;
  362. // // bottom: 0;
  363. // }
  364. // }
  365. // .new-login-r{
  366. // flex: 1 1;
  367. // width: 50%;
  368. // background: url("../../assets/images/nlogin-bg3.png") no-repeat;
  369. // position: relative;
  370. // .title{
  371. // text-align: center;
  372. // font-size: 26px;
  373. // font-weight: 700;
  374. // color: #01996a;
  375. // padding-top: 10%;
  376. // padding-bottom: 3%;
  377. // }
  378. // .btn {position: absolute;bottom: 10%;}
  379. // }
  380. // }
  381. // }
  382. // </style>
  383. <style lang="scss" scoped>
  384. $bg: #2d3a4b;
  385. $dark_gray: #999;
  386. $light_gray: #000;
  387. $bg: #ccc;
  388. $light_gray: #ccc;
  389. $cursor: #000;
  390. .login-container{
  391. position: relative;height: 100%;width: 100%;background: url("../../assets/images/nlogin-bg1.jpg") no-repeat;
  392. .new-login{
  393. width: 50%;height: 42%;position: absolute;left: 0;right: 0;bottom: 0;top: 0;margin: auto;
  394. .new-login-l{
  395. background: red;float:left;height:100%;width:50%;background: url("../../assets/images/nlogin-bg2.png") no-repeat;position: relative;
  396. img{position: absolute;left: 0;right: 0;bottom: 0;top: 0;margin: auto;width: 50%;height:23%;}
  397. }
  398. .new-login-r{
  399. background: #fff;float:left;height:100%;width:50%;position: relative;
  400. .title{margin-top: 10%;font-size: 20px;font-weight: 600;color: #019969;text-align: center;}
  401. .login-form{
  402. position: relative;width: 520px;max-width: 100%;overflow: hidden;height: 48%;
  403. .svg-container{padding: 6px 5px 6px 15px; color: $dark_gray; vertical-align: middle; width: 30px; display: inline-block;}
  404. .el-input {
  405. display: inline-block; width: 80%;
  406. }
  407. }
  408. .el-form-item {
  409. border: none; background: #fff; border-radius: 5px; color: #999;width: 73%; margin: 10px auto;height: 30%;
  410. /deep/.el-form-item__content {
  411. line-height: 16%; border-bottom: 1px solid #e7e7e7;
  412. }
  413. .el-form-item__content .el-input{
  414. /deep/.el-input__inner{border: none !important;}
  415. }
  416. }
  417. .rememberPassword{
  418. /deep/.el-form-item__content { line-height:16%; border: none;padding-bottom: 10px; span{padding-left: 5px;} }
  419. }
  420. .password{margin-top: 10px;margin-bottom: 20px;}
  421. .btn{
  422. position: absolute; overflow: hidden; width: 75%;left: 0;right: 0;bottom: 10%;margin: 0 auto;
  423. /deep/span{background:#01996a;border: #01996a;border-radius: 5px;line-height: 40px; text-align: center;color:#fff; display: block;}
  424. }
  425. }
  426. }
  427. }
  428. </style>