index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <template>
  2. <div class="login-container">
  3. <div class="flexBox">
  4. <div>
  5. <el-form
  6. ref="loginForm"
  7. :model="loginForm"
  8. :rules="loginRules"
  9. class="login-form"
  10. auto-complete="on"
  11. label-position="left"
  12. @submit.native.prevent="handleLogin"
  13. >
  14. <div class="flex">
  15. <div class="image-container">
  16. <div class="empty-height">
  17. <img class="logo" src="@/assets/login/logo.png" alt="" />
  18. </div>
  19. <el-carousel
  20. :interval="5000"
  21. arrow="always"
  22. height="440px"
  23. class="carousel"
  24. >
  25. <el-carousel-item v-for="item in banner" :key="item.id">
  26. <el-image :z-index="1" :src="item.imgCarouselUrl"></el-image>
  27. </el-carousel-item>
  28. </el-carousel>
  29. </div>
  30. <div class="right-container">
  31. <div class="empty-height" />
  32. <div class="form-container">
  33. <div class="flex title">
  34. <div
  35. class="title-item"
  36. :class="acitve == 'pas' ? 'acitve' : ''"
  37. @click="hanleTabs('pas')"
  38. >
  39. 密码登录
  40. </div>
  41. <div
  42. class="title-item"
  43. :class="acitve == 'wei' ? 'acitve' : ''"
  44. @click="hanleTabs('wei')"
  45. >
  46. 微信登录
  47. </div>
  48. </div>
  49. <transition name="slide">
  50. <div v-if="acitve == 'pas'">
  51. <el-form-item prop="username" class="input-box">
  52. <span class="svg-container">
  53. <el-image
  54. style="width: 20px; height: 20px"
  55. :src="require('@/assets/login/icon_001.png')"
  56. fit="contain "
  57. ></el-image>
  58. </span>
  59. <el-input
  60. ref="username"
  61. v-model="loginForm.username"
  62. placeholder="请输入用户名"
  63. name="username"
  64. type="text"
  65. tabindex="1"
  66. auto-complete="on"
  67. />
  68. </el-form-item>
  69. <el-form-item prop="password" class="input-box">
  70. <span class="svg-container">
  71. <el-image
  72. style="width: 20px; height: 20px"
  73. :src="require('@/assets/login/icon_002.png')"
  74. fit="contain "
  75. ></el-image>
  76. </span>
  77. <el-input
  78. :key="passwordType"
  79. ref="password"
  80. v-model="loginForm.password"
  81. :type="passwordType"
  82. placeholder="请输入密码"
  83. name="password"
  84. tabindex="2"
  85. auto-complete="off"
  86. @keyup.enter.native="handleLogin"
  87. />
  88. <span class="show-pwd" @click="showPwd">
  89. <svg-icon
  90. :icon-class="
  91. passwordType === 'password' ? 'eye' : 'eye-open'
  92. "
  93. />
  94. </span>
  95. </el-form-item>
  96. <div class="input-box">
  97. <el-form-item prop="codeValue">
  98. <span class="svg-container">
  99. <el-image
  100. style="width: 20px; height: 20px"
  101. :src="require('@/assets/login/icon_003.png')"
  102. fit="contain "
  103. ></el-image>
  104. </span>
  105. <el-input
  106. ref="codeValue"
  107. v-model="loginForm.codeValue"
  108. placeholder="请输入验证码"
  109. name="codeValue"
  110. type="text"
  111. tabindex="3"
  112. auto-complete="off"
  113. @keyup.enter.native="handleLogin"
  114. />
  115. </el-form-item>
  116. <div class="code" @click.stop="getCode">
  117. <img
  118. :src="'data:image/jpeg;base64,' + codeImage"
  119. alt=""
  120. />
  121. </div>
  122. </div>
  123. <div class="checkbox">
  124. <div class="check-yes">
  125. <el-image
  126. style="width: 16px; height: 16px"
  127. :src="require('@/assets/login/icon_004.png')"
  128. fit="contain "
  129. ></el-image>
  130. <el-image
  131. v-if="isRemenberPw"
  132. class="yes"
  133. style="width: 11px; height: 11px"
  134. :src="require('@/assets/login/icon_005.png')"
  135. fit="contain "
  136. ></el-image>
  137. </div>
  138. <el-checkbox v-model="isRemenberPw"
  139. >记住账号密码</el-checkbox
  140. >
  141. </div>
  142. <div class="button-container">
  143. <el-button
  144. :loading="loading"
  145. type="primary"
  146. @click.native.prevent="handleLogin"
  147. >登录</el-button
  148. >
  149. </div>
  150. </div>
  151. <div v-else class="wei">
  152. <div style="width: 250px; height: 250px">
  153. <!-- <el-image
  154. style="width: 250px; height: 250px"
  155. :src="require('@/assets/login/icon_001.png')"
  156. fit="contain "
  157. ></el-image> -->
  158. </div>
  159. <div>
  160. <div class="wei-item-tip">使用手机微信扫码登录</div>
  161. <div class="wei-item-text">
  162. 网页版微信需要配合手机使用
  163. </div>
  164. </div>
  165. </div>
  166. </transition>
  167. </div>
  168. </div>
  169. </div>
  170. </el-form>
  171. </div>
  172. <div class="info">
  173. <div class="info-item">
  174. <a :href="companyList[0].icpRecordLink">{{
  175. companyList[0].icpRecord
  176. }}</a>
  177. <div
  178. style="margin: 0 20px"
  179. v-if="companyList[0].companyName && companyList[0].icpRecordLink"
  180. >
  181. |
  182. </div>
  183. <a :href="companyList[0].pubSecurityRecordLink">
  184. <el-image
  185. style="width: 14px; height: 16px"
  186. :src="require('@/assets/login/icon_0001.png')"
  187. ></el-image>
  188. {{ companyList[0].pubSecurityRecord }}</a
  189. >
  190. </div>
  191. <div>{{ companyList[0].companyName }}</div>
  192. </div>
  193. </div>
  194. </div>
  195. </template>
  196. <script>
  197. import { validUsername } from "@/utils/validate";
  198. import Cookies from "js-cookie";
  199. import { getCode, getCompanyList, getList } from "@/api/user";
  200. export default {
  201. name: "Login",
  202. data() {
  203. const validateUsername = (rule, value, callback) => {
  204. if (value.length <= 0) {
  205. callback(new Error("请输入用户名"));
  206. } else {
  207. callback();
  208. }
  209. };
  210. const validatePassword = (rule, value, callback) => {
  211. if (value.length <= 0) {
  212. callback(new Error("请输入密码"));
  213. } else {
  214. callback();
  215. }
  216. };
  217. const validateCode = (rule, value, callback) => {
  218. if (value.length <= 0) {
  219. callback(new Error("请输入验证码"));
  220. } else {
  221. callback();
  222. }
  223. };
  224. return {
  225. loginForm: {
  226. username: "",
  227. password: "",
  228. code: "",
  229. codeValue: "",
  230. },
  231. loginRules: {
  232. username: [
  233. { required: true, trigger: "change", validator: validateUsername },
  234. ],
  235. password: [
  236. { required: true, trigger: "change", validator: validatePassword },
  237. ],
  238. codeValue: [
  239. { required: true, trigger: "change", validator: validateCode },
  240. ],
  241. },
  242. loading: false,
  243. passwordType: "password",
  244. redirect: undefined,
  245. isRemenberPw: false,
  246. codeImage: "",
  247. acitve: "pas",
  248. banner: [],
  249. companyList: [],
  250. };
  251. },
  252. watch: {
  253. $route: {
  254. handler: function (route) {
  255. this.redirect = route.query && route.query.redirect;
  256. },
  257. immediate: true,
  258. },
  259. },
  260. created() {
  261. // 获取缓存信息
  262. if (localStorage.getItem("supply_login")) {
  263. let storageData = JSON.parse(localStorage.getItem("supply_login"));
  264. this.loginForm.username = storageData.username;
  265. this.isRemenberPw = storageData.isRemenberPw;
  266. }
  267. if (this.isRemenberPw) {
  268. this.getCookie();
  269. }
  270. this.getCode();
  271. this.getList();
  272. this.getCompanyList();
  273. },
  274. methods: {
  275. // 获取验证码
  276. getCode() {
  277. getCode().then((res) => {
  278. console.log(res);
  279. this.loginForm.code = res.data.code;
  280. this.codeImage = res.data.pic;
  281. });
  282. },
  283. getCompanyList() {
  284. getCompanyList().then((res) => {
  285. this.companyList = res.data;
  286. });
  287. },
  288. getList() {
  289. getList().then((res) => {
  290. this.banner = res.data;
  291. });
  292. },
  293. hanleTabs(val) {
  294. this.acitve = val;
  295. },
  296. // 显示隐藏密码
  297. showPwd() {
  298. if (this.passwordType === "password") {
  299. this.passwordType = "";
  300. } else {
  301. this.passwordType = "password";
  302. }
  303. this.$nextTick(() => {
  304. this.$refs.password.focus();
  305. });
  306. },
  307. // 登录
  308. handleLogin() {
  309. console.log(this.loginForm, "lll");
  310. this.$refs.loginForm.validate((valid) => {
  311. if (valid) {
  312. this.loading = true;
  313. this.$store
  314. .dispatch("user/login", this.loginForm)
  315. .then(() => {
  316. console.log(this.redirect);
  317. this.$router.push({ path: this.redirect || "/" });
  318. this.saveUnAndPw();
  319. this.$store.commit("user/showMessage", "yes");
  320. this.loading = false;
  321. })
  322. .catch(() => {
  323. this.getCode();
  324. this.loginForm.codeValue = "";
  325. this.loading = false;
  326. });
  327. } else {
  328. console.log("error submit!!");
  329. return false;
  330. }
  331. });
  332. },
  333. // 处理账号密码的储存
  334. saveUnAndPw() {
  335. let storageData = {
  336. username: this.loginForm.username,
  337. isRemenberPw: this.isRemenberPw,
  338. };
  339. localStorage.setItem("supply_login", JSON.stringify(storageData));
  340. if (this.isRemenberPw) {
  341. this.setCookie(this.loginForm.username, this.loginForm.password, 7);
  342. }
  343. },
  344. //设置cookie
  345. setCookie(c_name, c_pwd, exdays) {
  346. var exdate = new Date(); //获取时间
  347. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天数
  348. //字符串拼接cookie
  349. window.document.cookie =
  350. "supply_username" +
  351. "=" +
  352. c_name +
  353. ";path=/;expires=" +
  354. exdate.toGMTString();
  355. window.document.cookie =
  356. "supply_password" +
  357. "=" +
  358. c_pwd +
  359. ";path=/;expires=" +
  360. exdate.toGMTString();
  361. },
  362. //读取cookie
  363. getCookie: function () {
  364. if (document.cookie.length > 0) {
  365. var arr = document.cookie.split("; "); //这里显示的格式需要切割一下自己可输出看下
  366. for (var i = 0; i < arr.length; i++) {
  367. var arr2 = arr[i].split("="); //再次切割
  368. //判断查找相对应的值
  369. if (arr2[0] == "supply_username") {
  370. this.loginForm.username = arr2[1]; //保存到保存数据的地方
  371. } else if (arr2[0] == "supply_password") {
  372. this.loginForm.password = arr2[1];
  373. }
  374. }
  375. }
  376. },
  377. //清除cookie
  378. clearCookie: function () {
  379. this.setCookie("", "", -1); //修改2值都为空,天数为负1天就好了
  380. },
  381. },
  382. };
  383. </script>
  384. <style lang="scss">
  385. /* 修复input 背景不协调 和光标变色 */
  386. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  387. $bg: #283443;
  388. $light_gray: #fff;
  389. $cursor: #fff;
  390. $back: #333;
  391. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  392. .login-container .el-input input {
  393. color: $cursor;
  394. }
  395. }
  396. /* reset element-ui css */
  397. .login-container {
  398. background: url("~@/assets/login/background.png") center center;
  399. background-size: cover;
  400. .el-input {
  401. display: inline-block;
  402. height: 47px;
  403. width: 85%;
  404. input {
  405. background: transparent;
  406. border: 0px;
  407. -webkit-appearance: none;
  408. border-radius: 0px;
  409. padding: 12px 5px 12px 15px;
  410. color: $back;
  411. height: 47px;
  412. caret-color: $back;
  413. border-bottom: none !important;
  414. &:-webkit-autofill {
  415. box-shadow: 0 0 0px 1000px $cursor inset !important;
  416. -webkit-text-fill-color: $back !important;
  417. }
  418. }
  419. }
  420. .el-carousel__arrow--left,
  421. .el-carousel__arrow--right {
  422. display: none;
  423. }
  424. .carousel {
  425. border-top-left-radius: 15px;
  426. border-bottom-left-radius: 15px;
  427. overflow: hidden;
  428. }
  429. .el-form-item {
  430. border: 1px solid rgba(255, 255, 255, 0.1);
  431. // background: rgba(0, 0, 0, 0.1);
  432. border-radius: 5px;
  433. color: #454545;
  434. margin-bottom: 10px;
  435. }
  436. .el-checkbox__input {
  437. display: none;
  438. }
  439. .el-form-item__error {
  440. left: 30px;
  441. }
  442. .el-form-item__content {
  443. display: flex;
  444. align-items: center;
  445. line-height: 0;
  446. }
  447. .show-pwd {
  448. line-height: 40px;
  449. }
  450. .el-checkbox__input.is-checked + .el-checkbox__label {
  451. color: #4684f4db;
  452. }
  453. .checkbox {
  454. display: flex;
  455. align-items: center;
  456. margin-left: 1px;
  457. .check-yes {
  458. position: relative;
  459. line-height: 0;
  460. }
  461. .yes {
  462. position: absolute;
  463. left: 50%;
  464. top: 50%;
  465. transform: translate(-50%, -50%);
  466. }
  467. .el-checkbox {
  468. margin: 0 !important;
  469. }
  470. }
  471. /* 可以设置不同的进入和离开动画 */
  472. /* 设置持续时间和动画函数 */
  473. .slide-fade-enter-active {
  474. transition: all 0.3s ease;
  475. }
  476. .slide-fade-leave-active {
  477. transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
  478. }
  479. .slide-fade-leave-active {
  480. transform: translateX(10px);
  481. opacity: 0;
  482. }
  483. .wei {
  484. display: flex;
  485. flex-direction: column;
  486. justify-content: center;
  487. align-items: center;
  488. margin-top: 30px;
  489. text-align: center;
  490. text-align-last: center;
  491. &-item-tip {
  492. height: 19px;
  493. font-size: 20px;
  494. margin-top: 17px;
  495. }
  496. &-item-text {
  497. height: 12px;
  498. font-size: 14px;
  499. margin-top: 17px;
  500. color: #999;
  501. }
  502. }
  503. }
  504. </style>
  505. <style lang="scss" scoped>
  506. $bg: #2d3a4b;
  507. $dark_gray: #889aa4;
  508. $light_gray: #eee;
  509. .info {
  510. display: flex;
  511. align-items: center;
  512. flex-direction: column;
  513. justify-content: center;
  514. width: 1080px;
  515. margin-top: 50px;
  516. line-height: 30px;
  517. text-align: center;
  518. text-align-last: center;
  519. color: #fff;
  520. }
  521. .info-item {
  522. display: flex;
  523. align-items: center;
  524. justify-content: center;
  525. }
  526. .title-item {
  527. display: flex;
  528. flex-direction: column;
  529. justify-content: center;
  530. align-items: center;
  531. margin: 0 30px;
  532. cursor: pointer;
  533. font-size: 24px;
  534. color: #666666;
  535. line-height: 40px;
  536. border-bottom: 3px solid #ffffff;
  537. }
  538. .acitve {
  539. font-weight: bold;
  540. color: #4684f4;
  541. border-bottom: 3px solid #4684f4;
  542. }
  543. .flexBox {
  544. display: flex;
  545. padding-top: calc(50vh - 230px);
  546. justify-content: space-between;
  547. flex-direction: column;
  548. align-items: center;
  549. }
  550. .input-box {
  551. position: relative;
  552. width: 360px;
  553. height: 50px;
  554. margin-bottom: 20px;
  555. background: #ffffff;
  556. border: 1px solid #e6e6e6 !important;
  557. border-radius: 4px;
  558. }
  559. .input-box:last-child {
  560. margin-bottom: 10px;
  561. }
  562. .flex {
  563. display: flex;
  564. flex-direction: row;
  565. }
  566. .empty-height {
  567. height: 46px;
  568. margin: 15px 0;
  569. }
  570. .logo {
  571. height: 46px;
  572. width: 460px;
  573. }
  574. .el-carousel__item:nth-child(2n) {
  575. background-color: #99a9bf;
  576. }
  577. .el-carousel__item:nth-child(2n + 1) {
  578. background-color: #d3dce6;
  579. }
  580. .login-container {
  581. min-height: 100%;
  582. width: 100%;
  583. background-color: $bg;
  584. overflow: hidden;
  585. .login-form {
  586. position: relative;
  587. width: 1920px;
  588. max-width: 100%;
  589. height: 100%;
  590. display: flex;
  591. flex-direction: column;
  592. align-items: center;
  593. }
  594. .image-container {
  595. width: 700px;
  596. height: 516px;
  597. // overflow: hidden;
  598. }
  599. .right-container {
  600. width: 440px;
  601. height: 516px;
  602. .form-container {
  603. height: 440px;
  604. padding: 20px 30px 27px 40px;
  605. background: #fff;
  606. border-radius: 0 15px 15px 0;
  607. .title {
  608. justify-content: center;
  609. letter-spacing: 4px;
  610. text-align: center;
  611. margin-bottom: 35px;
  612. }
  613. }
  614. }
  615. .tips {
  616. font-size: 14px;
  617. color: #fff;
  618. margin-bottom: 10px;
  619. span {
  620. &:first-of-type {
  621. margin-right: 16px;
  622. }
  623. }
  624. }
  625. .svg-container {
  626. margin: 0 0 0 14px;
  627. // padding: 6px 5px 6px 5px;
  628. color: #33aef7;
  629. vertical-align: middle;
  630. width: 30px;
  631. display: inline-block;
  632. }
  633. .title-container {
  634. border-radius: 15px 15px 0 0;
  635. overflow: hidden;
  636. img {
  637. width: 100%;
  638. display: block;
  639. }
  640. }
  641. .show-pwd {
  642. position: absolute;
  643. right: 30px;
  644. top: 7px;
  645. font-size: 16px;
  646. color: $dark_gray;
  647. cursor: pointer;
  648. user-select: none;
  649. }
  650. .code {
  651. position: absolute;
  652. right: 30px;
  653. top: 7px;
  654. z-index: 99;
  655. cursor: pointer;
  656. img {
  657. height: 30px;
  658. }
  659. }
  660. .button-container {
  661. text-align: center;
  662. margin-top: 20px;
  663. button {
  664. font-size: 16px;
  665. width: 100%;
  666. height: 45px;
  667. border-radius: 4px;
  668. background: #4684f4;
  669. box-shadow: 2px 3px 8px 0px #4684f46b;
  670. }
  671. }
  672. }
  673. ::v-deep .el-form-item__error {
  674. color: #f56c6c;
  675. font-size: 12px;
  676. line-height: 1;
  677. padding-top: 6px;
  678. position: absolute;
  679. top: 100%;
  680. left: 0;
  681. }
  682. @media only screen and (max-width: 600px) {
  683. .image-container {
  684. display: none;
  685. }
  686. .form-container {
  687. border-radius: 15px !important;
  688. }
  689. }
  690. </style>