index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div class="login-container">
  3. <div id="particles-js">
  4. <vue-particles
  5. color="#dedede"
  6. :particle-opacity="0.7"
  7. :particles-number="80"
  8. shape-type="circle"
  9. :particle-size="4"
  10. lines-color="#dedede"
  11. :lines-width="1"
  12. :line-linked="true"
  13. :line-opacity="0.4"
  14. :lines-distance="150"
  15. :move-speed="3"
  16. :hover-effect="true"
  17. hover-mode="grab"
  18. :click-effect="true"
  19. click-mode="push"
  20. />
  21. </div>
  22. <div class="login-weaper animated bounceInDown">
  23. <div class="login-left">
  24. <div class="login-time" v-text="currentTime" />
  25. <img :src="logo" alt="" class="img">
  26. <p class="title" v-text="title" />
  27. </div>
  28. <div class="login-border">
  29. <div class="login-main">
  30. <div class="login-title"> 用户登录 </div>
  31. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
  32. <el-form-item prop="username">
  33. <span class="svg-container">
  34. <i class="el-icon-user" />
  35. </span>
  36. <el-input
  37. ref="username"
  38. v-model="loginForm.username"
  39. placeholder="用户名"
  40. name="username"
  41. type="text"
  42. tabindex="1"
  43. autocomplete="on"
  44. />
  45. </el-form-item>
  46. <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
  47. <el-form-item prop="password">
  48. <span class="svg-container">
  49. <svg-icon icon-class="password" />
  50. </span>
  51. <el-input
  52. :key="passwordType"
  53. ref="password"
  54. v-model="loginForm.password"
  55. :type="passwordType"
  56. placeholder="密码"
  57. name="password"
  58. tabindex="2"
  59. autocomplete="on"
  60. @keyup.native="checkCapslock"
  61. @blur="capsTooltip = false"
  62. @keyup.enter.native="handleLogin"
  63. />
  64. <span class="show-pwd" @click="showPwd">
  65. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  66. </span>
  67. </el-form-item>
  68. </el-tooltip>
  69. <!-- <el-form-item prop="code" style="width: 66%;float: left;">
  70. <span class="svg-container">
  71. <svg-icon icon-class="validCode" />
  72. </span>
  73. <el-input
  74. ref="username"
  75. v-model="loginForm.code"
  76. placeholder="验证码"
  77. name="username"
  78. type="text"
  79. tabindex="3"
  80. maxlength="5"
  81. autocomplete="off"
  82. style=" width: 75%;"
  83. @keyup.enter.native="handleLogin"
  84. />
  85. </el-form-item> -->
  86. <!-- <div class="login-code" style="cursor:pointer; width: 30%;height: 48px;float: right;background-color: #f0f1f5;">
  87. <img style="height: 48px;width: 100%;border: 1px solid rgba(0,0,0, 0.1);border-radius:5px;" :src="codeUrl" @click="getCode">
  88. </div> -->
  89. <!-- <div prop="code" style="width: 100%;float: left;margin-bottom: 13px">
  90. <el-checkbox v-model="isLdap">LDAP登陆</el-checkbox>
  91. </div> -->
  92. <el-button :loading="loading" type="primary" style="width:100%;padding:12px 20px;margin-bottom:30px;" @click.native.prevent="handleLogin">
  93. <span v-if="!loading">登 录</span>
  94. <span v-else>登 录 中...</span>
  95. </el-button>
  96. </el-form>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. <script>
  103. import { getCodeImg } from '@/api/login'
  104. import moment from 'moment'
  105. import { mapGetters } from 'vuex'
  106. export default {
  107. name: 'Login',
  108. data() {
  109. const validateUsername = (rule, value, callback) => {
  110. // validUsername
  111. if (!value) {
  112. callback(new Error('请输入用户名'))
  113. } else {
  114. callback()
  115. }
  116. }
  117. const validatePassword = (rule, value, callback) => {
  118. if (value.length < 6) {
  119. callback(new Error('密码必须大于六位'))
  120. } else {
  121. callback()
  122. }
  123. }
  124. return {
  125. codeUrl: '',
  126. cookiePassword: '',
  127. loginForm: {
  128. username: '',
  129. password: '',
  130. rememberMe: false,
  131. code: '',
  132. uuid: '',
  133. loginType: 1
  134. },
  135. loginRules: {
  136. username: [
  137. { required: true, trigger: 'blur', validator: validateUsername }
  138. ],
  139. password: [
  140. { required: true, trigger: 'blur', validator: validatePassword }
  141. ]
  142. },
  143. passwordType: 'password',
  144. capsTooltip: false,
  145. loading: false,
  146. redirect: undefined,
  147. otherQuery: {},
  148. currentTime: null
  149. }
  150. },
  151. computed: {
  152. ...mapGetters(['title', 'logo', 'isLdap'])
  153. },
  154. watch: {
  155. $route: {
  156. handler: function(route) {
  157. const query = route.query
  158. if (query) {
  159. this.redirect = query.redirect
  160. this.otherQuery = this.getOtherQuery(query)
  161. }
  162. },
  163. immediate: true
  164. }
  165. },
  166. created() {
  167. this.getCode()
  168. // window.addEventListener('storage', this.afterQRScan)
  169. this.getCurrentTime()
  170. },
  171. mounted() {
  172. if (this.loginForm.username === '') {
  173. this.$refs.username.focus()
  174. } else if (this.loginForm.password === '') {
  175. this.$refs.password.focus()
  176. }
  177. },
  178. destroyed() {
  179. clearInterval(this.timer)
  180. // window.removeEventListener('storage', this.afterQRScan)
  181. },
  182. methods: {
  183. getCurrentTime() {
  184. this.timer = setInterval(_ => {
  185. this.currentTime = moment().format('YYYY-MM-DD HH时mm分ss秒')
  186. }, 1000)
  187. },
  188. getCode() {
  189. getCodeImg().then(res => {
  190. if (res !== undefined) {
  191. this.codeUrl = res.data
  192. this.loginForm.uuid = res.id
  193. }
  194. })
  195. },
  196. checkCapslock({ shiftKey, key } = {}) {
  197. if (key && key.length === 1) {
  198. if (shiftKey && (key >= 'a' && key <= 'z') || !shiftKey && (key >= 'A' && key <= 'Z')) {
  199. this.capsTooltip = true
  200. } else {
  201. this.capsTooltip = false
  202. }
  203. }
  204. if (key === 'CapsLock' && this.capsTooltip === true) {
  205. this.capsTooltip = false
  206. }
  207. },
  208. showPwd() {
  209. if (this.passwordType === 'password') {
  210. this.passwordType = ''
  211. } else {
  212. this.passwordType = 'password'
  213. }
  214. this.$nextTick(() => {
  215. this.$refs.password.focus()
  216. })
  217. },
  218. handleLogin() {
  219. this.$refs.loginForm.validate(valid => {
  220. if (valid) {
  221. if (this.isLdap) {
  222. this.loginForm.loginType = 1
  223. } else {
  224. this.loginForm.loginType = 0
  225. }
  226. this.loading = true
  227. this.$store.dispatch('user/login', this.loginForm)
  228. .then(() => {
  229. // this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
  230. this.$router.push({ path: '/' })
  231. this.loading = false
  232. })
  233. .catch(() => {
  234. this.loading = false
  235. // this.getCode()
  236. })
  237. } else {
  238. return false
  239. }
  240. })
  241. },
  242. getOtherQuery(query) {
  243. return Object.keys(query).reduce((acc, cur) => {
  244. if (cur !== 'redirect') {
  245. acc[cur] = query[cur]
  246. }
  247. return acc
  248. }, {})
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss" scoped>
  254. /* 修复input 背景不协调 和光标变色 */
  255. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  256. $bg:#283443;
  257. $light_gray:#fff;
  258. $cursor: #fff;
  259. .login-container{
  260. display: -webkit-box;
  261. display: -ms-flexbox;
  262. display: flex;
  263. -webkit-box-align: center;
  264. -ms-flex-align: center;
  265. align-items: center;
  266. width: 100%;
  267. height: 100%;
  268. margin: 0 auto;
  269. background: url("../../assets/login.png") no-repeat;
  270. background-color: #304175;
  271. position: relative;
  272. background-size: cover;
  273. height: 100vh;
  274. background-position: 50%;
  275. }
  276. #particles-js{
  277. z-index: 1;
  278. width: 100%;
  279. height: 100%;
  280. position: absolute;
  281. }
  282. .login-weaper{
  283. margin: 0 auto;
  284. width: 1000px;
  285. -webkit-box-shadow: -4px 5px 10px rgba(0,0,0,.4);
  286. box-shadow: -4px 5px 10px rgba(0,0,0,.4);
  287. z-index: 1000;
  288. }
  289. .login-left{
  290. border-top-left-radius: 5px;
  291. border-bottom-left-radius: 5px;
  292. -webkit-box-pack: center;
  293. -ms-flex-pack: center;
  294. justify-content: center;
  295. -webkit-box-orient: vertical;
  296. -webkit-box-direction: normal;
  297. -ms-flex-direction: column;
  298. flex-direction: column;
  299. background-color: rgba(64,158,255,0);
  300. color: #fff;
  301. float: left;
  302. width: 50%;
  303. position: relative;
  304. min-height: 500px;
  305. -webkit-box-align: center;
  306. -ms-flex-align: center;
  307. align-items: center;
  308. display: -webkit-box;
  309. display: -ms-flexbox;
  310. display: flex;
  311. .login-time{
  312. position: absolute;
  313. left: 25px;
  314. top: 25px;
  315. width: 100%;
  316. color: #fff;
  317. opacity: .9;
  318. font-size: 18px;
  319. overflow: hidden;
  320. font-weight: 500;
  321. }
  322. }
  323. .login-left .img{
  324. width: 120px;
  325. height: 120px;
  326. border-radius: 3px;
  327. }
  328. .login-left .title {
  329. text-align: center;
  330. color: #fff;
  331. letter-spacing: 2px;
  332. font-size: 30px;
  333. font-weight: 600;
  334. }
  335. .login-border{
  336. position: relative;
  337. min-height: 500px;
  338. -webkit-box-align: center;
  339. -ms-flex-align: center;
  340. align-items: center;
  341. display: -webkit-box;
  342. display: -ms-flexbox;
  343. display: flex;
  344. border-left: none;
  345. border-top-right-radius: 5px;
  346. border-bottom-right-radius: 5px;
  347. color: #fff;
  348. background-color: hsla(0,0%,100%,.9);
  349. width: 50%;
  350. float: left;
  351. }
  352. .login-main{
  353. margin: 0 auto;
  354. width: 65%;
  355. }
  356. .login-title{
  357. color: #333;
  358. margin-bottom: 40px;
  359. font-weight: 500;
  360. font-size: 22px;
  361. text-align: center;
  362. letter-spacing: 4px;
  363. }
  364. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  365. .login-container .el-input input {
  366. color: $cursor;
  367. }
  368. }
  369. /* reset element-ui css */
  370. .login-container {
  371. /deep/ .el-input {
  372. display: inline-block;
  373. height: 47px;
  374. width: 85%;
  375. input {
  376. background: transparent;
  377. border: 0px;
  378. -webkit-appearance: none;
  379. border-radius: 0px;
  380. padding: 12px 5px 12px 15px;
  381. color: #333;
  382. height: 47px;
  383. caret-color: #333;
  384. &:-webkit-autofill {
  385. box-shadow: 0 0 0px 1000px $bg inset !important;
  386. -webkit-text-fill-color: $cursor !important;
  387. }
  388. }
  389. }
  390. .el-form-item {
  391. border: 1px solid rgba(0,0,0, 0.1);
  392. background: rgba(255, 255, 255, 0.8);
  393. border-radius: 5px;
  394. color: #454545;
  395. }
  396. }
  397. $bg:#2d3a4b;
  398. $dark_gray:#889aa4;
  399. $light_gray:#eee;
  400. .login-container {
  401. .tips {
  402. font-size: 14px;
  403. color: #fff;
  404. margin-bottom: 10px;
  405. span {
  406. &:first-of-type {
  407. margin-right: 16px;
  408. }
  409. }
  410. }
  411. .svg-container {
  412. padding: 6px 5px 6px 15px;
  413. color: $dark_gray;
  414. vertical-align: middle;
  415. width: 30px;
  416. display: inline-block;
  417. }
  418. .title-container {
  419. position: relative;
  420. .title {
  421. font-size: 26px;
  422. color: $light_gray;
  423. margin: 0px auto 40px auto;
  424. text-align: center;
  425. font-weight: bold;
  426. }
  427. }
  428. .show-pwd {
  429. position: absolute;
  430. right: 10px;
  431. top: 7px;
  432. font-size: 16px;
  433. color: $dark_gray;
  434. cursor: pointer;
  435. user-select: none;
  436. }
  437. .thirdparty-button {
  438. position: absolute;
  439. right: 0;
  440. bottom: 6px;
  441. }
  442. @media only screen and (max-width: 470px) {
  443. .thirdparty-button {
  444. display: none;
  445. }
  446. }
  447. }
  448. </style>