dbc72c0bf45d87f0cc4ce3646eafe085fac88223.svn-base 14 KB

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