index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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.loading = false;
  314. })
  315. .catch(() => {
  316. this.getCode();
  317. this.loginForm.codeValue = "";
  318. this.loading = false;
  319. });
  320. } else {
  321. console.log("error submit!!");
  322. return false;
  323. }
  324. });
  325. },
  326. // 处理账号密码的储存
  327. saveUnAndPw() {
  328. let storageData = {
  329. username: this.loginForm.username,
  330. isRemenberPw: this.isRemenberPw,
  331. };
  332. localStorage.setItem("supply_login", JSON.stringify(storageData));
  333. if (this.isRemenberPw) {
  334. this.setCookie(this.loginForm.username, this.loginForm.password, 7);
  335. }
  336. },
  337. //设置cookie
  338. setCookie(c_name, c_pwd, exdays) {
  339. var exdate = new Date(); //获取时间
  340. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天数
  341. //字符串拼接cookie
  342. window.document.cookie =
  343. "supply_username" +
  344. "=" +
  345. c_name +
  346. ";path=/;expires=" +
  347. exdate.toGMTString();
  348. window.document.cookie =
  349. "supply_password" +
  350. "=" +
  351. c_pwd +
  352. ";path=/;expires=" +
  353. exdate.toGMTString();
  354. },
  355. //读取cookie
  356. getCookie: function () {
  357. if (document.cookie.length > 0) {
  358. var arr = document.cookie.split("; "); //这里显示的格式需要切割一下自己可输出看下
  359. for (var i = 0; i < arr.length; i++) {
  360. var arr2 = arr[i].split("="); //再次切割
  361. //判断查找相对应的值
  362. if (arr2[0] == "supply_username") {
  363. this.loginForm.username = arr2[1]; //保存到保存数据的地方
  364. } else if (arr2[0] == "supply_password") {
  365. this.loginForm.password = arr2[1];
  366. }
  367. }
  368. }
  369. },
  370. //清除cookie
  371. clearCookie: function () {
  372. this.setCookie("", "", -1); //修改2值都为空,天数为负1天就好了
  373. },
  374. },
  375. };
  376. </script>
  377. <style lang="scss">
  378. /* 修复input 背景不协调 和光标变色 */
  379. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  380. $bg: #283443;
  381. $light_gray: #fff;
  382. $cursor: #fff;
  383. $back: #333;
  384. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  385. .login-container .el-input input {
  386. color: $cursor;
  387. }
  388. }
  389. /* reset element-ui css */
  390. .login-container {
  391. background: url("~@/assets/login/background.png") center center;
  392. background-size: cover;
  393. .el-input {
  394. display: inline-block;
  395. height: 47px;
  396. width: 85%;
  397. input {
  398. background: transparent;
  399. border: 0px;
  400. -webkit-appearance: none;
  401. border-radius: 0px;
  402. padding: 12px 5px 12px 15px;
  403. color: $back;
  404. height: 47px;
  405. caret-color: $back;
  406. border-bottom: none !important;
  407. &:-webkit-autofill {
  408. box-shadow: 0 0 0px 1000px $cursor inset !important;
  409. -webkit-text-fill-color: $back !important;
  410. }
  411. }
  412. }
  413. .el-carousel__arrow--left,
  414. .el-carousel__arrow--right {
  415. display: none;
  416. }
  417. .carousel {
  418. border-top-left-radius: 15px;
  419. border-bottom-left-radius: 15px;
  420. overflow: hidden;
  421. }
  422. .el-form-item {
  423. border: 1px solid rgba(255, 255, 255, 0.1);
  424. // background: rgba(0, 0, 0, 0.1);
  425. border-radius: 5px;
  426. color: #454545;
  427. margin-bottom: 10px;
  428. }
  429. .el-checkbox__input {
  430. display: none;
  431. }
  432. .el-form-item__error {
  433. left: 30px;
  434. }
  435. .el-form-item__content {
  436. display: flex;
  437. align-items: center;
  438. line-height: 0;
  439. }
  440. .show-pwd {
  441. line-height: 40px;
  442. }
  443. .el-checkbox__input.is-checked + .el-checkbox__label {
  444. color: #4684f4db;
  445. }
  446. .checkbox {
  447. display: flex;
  448. align-items: center;
  449. margin-left: 1px;
  450. .check-yes {
  451. position: relative;
  452. line-height: 0;
  453. }
  454. .yes {
  455. position: absolute;
  456. left: 50%;
  457. top: 50%;
  458. transform: translate(-50%, -50%);
  459. }
  460. .el-checkbox {
  461. margin: 0 !important;
  462. }
  463. }
  464. /* 可以设置不同的进入和离开动画 */
  465. /* 设置持续时间和动画函数 */
  466. .slide-fade-enter-active {
  467. transition: all 0.3s ease;
  468. }
  469. .slide-fade-leave-active {
  470. transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
  471. }
  472. .slide-fade-leave-active {
  473. transform: translateX(10px);
  474. opacity: 0;
  475. }
  476. .wei {
  477. display: flex;
  478. flex-direction: column;
  479. justify-content: center;
  480. align-items: center;
  481. margin-top: 30px;
  482. text-align: center;
  483. text-align-last: center;
  484. &-item-tip {
  485. height: 19px;
  486. font-size: 20px;
  487. margin-top: 17px;
  488. }
  489. &-item-text {
  490. height: 12px;
  491. font-size: 14px;
  492. margin-top: 17px;
  493. color: #999;
  494. }
  495. }
  496. }
  497. </style>
  498. <style lang="scss" scoped>
  499. $bg: #2d3a4b;
  500. $dark_gray: #889aa4;
  501. $light_gray: #eee;
  502. .info {
  503. display: flex;
  504. align-items: center;
  505. flex-direction: column;
  506. justify-content: center;
  507. width: 1080px;
  508. margin-top: 50px;
  509. line-height: 30px;
  510. text-align: center;
  511. text-align-last: center;
  512. color: #fff;
  513. }
  514. .info-item {
  515. display: flex;
  516. align-items: center;
  517. justify-content: center;
  518. }
  519. .title-item {
  520. display: flex;
  521. flex-direction: column;
  522. justify-content: center;
  523. align-items: center;
  524. margin: 0 30px;
  525. cursor: pointer;
  526. font-size: 24px;
  527. color: #666666;
  528. line-height: 40px;
  529. border-bottom: 3px solid #FFFFFF;
  530. }
  531. .acitve {
  532. font-weight: bold;
  533. color: #4684f4;
  534. border-bottom: 3px solid #4684f4;
  535. }
  536. .flexBox {
  537. display: flex;
  538. padding-top: calc(50vh - 230px);
  539. justify-content: space-between;
  540. flex-direction: column;
  541. align-items: center;
  542. }
  543. .input-box {
  544. position: relative;
  545. width: 360px;
  546. height: 50px;
  547. margin-bottom: 20px;
  548. background: #ffffff;
  549. border: 1px solid #e6e6e6 !important;
  550. border-radius: 4px;
  551. }
  552. .input-box:last-child {
  553. margin-bottom: 10px;
  554. }
  555. .flex {
  556. display: flex;
  557. flex-direction: row;
  558. }
  559. .empty-height {
  560. height: 46px;
  561. margin: 15px 0;
  562. }
  563. .logo {
  564. height: 46px;
  565. width: 460px;
  566. }
  567. .el-carousel__item:nth-child(2n) {
  568. background-color: #99a9bf;
  569. }
  570. .el-carousel__item:nth-child(2n + 1) {
  571. background-color: #d3dce6;
  572. }
  573. .login-container {
  574. min-height: 100%;
  575. width: 100%;
  576. background-color: $bg;
  577. overflow: hidden;
  578. .login-form {
  579. position: relative;
  580. width: 1920px;
  581. max-width: 100%;
  582. height: 100%;
  583. display: flex;
  584. flex-direction: column;
  585. align-items: center;
  586. }
  587. .image-container {
  588. width: 700px;
  589. height: 516px;
  590. // overflow: hidden;
  591. }
  592. .right-container {
  593. width: 440px;
  594. height: 516px;
  595. .form-container {
  596. height: 440px;
  597. padding: 20px 30px 27px 40px;
  598. background: #fff;
  599. border-radius: 0 15px 15px 0;
  600. .title {
  601. justify-content: center;
  602. letter-spacing: 4px;
  603. text-align: center;
  604. margin-bottom: 35px;
  605. }
  606. }
  607. }
  608. .tips {
  609. font-size: 14px;
  610. color: #fff;
  611. margin-bottom: 10px;
  612. span {
  613. &:first-of-type {
  614. margin-right: 16px;
  615. }
  616. }
  617. }
  618. .svg-container {
  619. margin: 0 0 0 14px;
  620. // padding: 6px 5px 6px 5px;
  621. color: #33aef7;
  622. vertical-align: middle;
  623. width: 30px;
  624. display: inline-block;
  625. }
  626. .title-container {
  627. border-radius: 15px 15px 0 0;
  628. overflow: hidden;
  629. img {
  630. width: 100%;
  631. display: block;
  632. }
  633. }
  634. .show-pwd {
  635. position: absolute;
  636. right: 30px;
  637. top: 7px;
  638. font-size: 16px;
  639. color: $dark_gray;
  640. cursor: pointer;
  641. user-select: none;
  642. }
  643. .code {
  644. position: absolute;
  645. right: 30px;
  646. top: 7px;
  647. z-index: 99;
  648. cursor: pointer;
  649. img {
  650. height: 30px;
  651. }
  652. }
  653. .button-container {
  654. text-align: center;
  655. margin-top: 20px;
  656. button {
  657. font-size: 16px;
  658. width: 100%;
  659. height: 45px;
  660. border-radius: 4px;
  661. background: #4684f4;
  662. box-shadow: 2px 3px 8px 0px #4684f46b;
  663. }
  664. }
  665. }
  666. @media only screen and (max-width: 600px) {
  667. .image-container {
  668. display: none;
  669. }
  670. .form-container {
  671. border-radius: 15px !important;
  672. }
  673. }
  674. </style>