41439b973167b653e4005d8324546e62cfffabfe.svn-base 11 KB

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