index.vue 20 KB

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