index.vue 22 KB

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