index.vue 18 KB

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