login.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. <template>
  2. <div class="backdrop">
  3. <el-container>
  4. <!-- logo -->
  5. <img class="zap-logo" src="../assets/images/login_logo.png" alt="">
  6. <el-main>
  7. <!-- 中间部分 -->
  8. <div class="login">
  9. <div class="login-left">
  10. <img class="login-name" src="../assets/images/logo_name.png" alt="">
  11. <img class="login-illustration" src="../assets/images/login_img.png" alt="">
  12. </div>
  13. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  14. <template v-if="!scanningLogin">
  15. <div class="zap-2dcode">
  16. <img class="zap-2dcode__text" src="../assets/images/code1_1.png" alt="">
  17. <img class="zap-2dcode__img" src="../assets/images/code1_2.gif" alt="" @click="scanningLogin=true">
  18. </div>
  19. <el-tabs v-model="activeName" class="zap-tabs" @tab-click="changeLoginType">
  20. <el-tab-pane label="密码登录" name="login_password">
  21. <el-form-item prop="username">
  22. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  23. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item prop="password">
  27. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin">
  28. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  29. </el-input>
  30. </el-form-item>
  31. <el-form-item prop="code">
  32. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 53%;" @keyup.enter.native="handleLogin">
  33. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  34. </el-input>
  35. <div class="login-code">
  36. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  37. </div>
  38. </el-form-item>
  39. <el-form-item style="width:100%;margin-bottom: 0;">
  40. <el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
  41. </el-form-item>
  42. <el-form-item style="width:100%;">
  43. <el-button :loading="loading" class="zap-button" size="medium" type="primary" @click.native.prevent="handleLogin">
  44. <span v-if="!loading">登 录</span>
  45. <span v-else>登 录 中...</span>
  46. </el-button>
  47. </el-form-item>
  48. <el-form-item>
  49. <div class="zap-agreement">
  50. <span class="zap-agreement__text">登录视为同意并遵守</span>
  51. <div class="zap-agreement__link">
  52. <span>《招采云链服务平台会员注册协议》</span>
  53. <span>《招采云链服务平台隐私政策》</span>
  54. </div>
  55. </div>
  56. </el-form-item>
  57. <!-- <el-divider class="divider_left"><span style="font-size:10px;word-break: keep-all;">第三方快捷登录</span></el-divider>
  58. <el-form-item style="width:100%;">
  59. <img :src="wxSrc" @mouseover="changeImg" @mouseleave="returnImg" @click="getWeChatImg" style="width:30px;margin-left: 77px;">
  60. </el-form-item> -->
  61. </el-tab-pane>
  62. <el-tab-pane label="验证码登录" name="login_shortMessage">
  63. <el-form-item prop="username">
  64. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="手机号">
  65. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  66. </el-input>
  67. </el-form-item>
  68. <el-form-item prop="code">
  69. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 53%;" @keyup.enter.native="handleLogin">
  70. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  71. </el-input>
  72. <div class="login-code">
  73. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  74. </div>
  75. </el-form-item>
  76. <el-form-item prop="cade">
  77. <el-input v-model="loginForm.shortMessageCode" type="text" maxlength="" auto-complete="off" placeholder="请输入验证码" id="" onkeydown="enterHandler(event)">
  78. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  79. <el-button class="zap-code-button" slot="suffix" @click="sendMessage" :disabled="sendShortMessageBtn">{{codeBtnWord}}</el-button>
  80. </el-input>
  81. </el-form-item>
  82. <el-form-item style="width:100%;">
  83. <el-button :loading="loading" class="zap-button" size="medium" type="primary" @click.native.prevent="handleLogin">
  84. <span v-if="!loading">登 录</span>
  85. <span v-else>登 录 中...</span>
  86. </el-button>
  87. </el-form-item>
  88. <el-form-item>
  89. <div class="zap-agreement">
  90. <span class="zap-agreement__text">登录视为同意并遵守</span>
  91. <div class="zap-agreement__link">
  92. <span>《招采云链服务平台会员注册协议》</span>
  93. <span>《招采云链服务平台隐私政策》</span>
  94. </div>
  95. </div>
  96. </el-form-item>
  97. </el-tab-pane>
  98. </el-tabs>
  99. </template>
  100. <!-- 手机扫码 -->
  101. <div v-else class="zap-scanning">
  102. <div class="zap-2dcode">
  103. <img class="zap-2dcode__img" src="../assets/images/code1_3.gif" alt="" @click="scanningLogin=false">
  104. </div>
  105. <div class="zap-scanning__title">手机扫码</div>
  106. <img class="zap-scanning__img" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201804%2F28%2F20180428114906_ulvqd.jpg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1634225094&t=7acfc568424bf9781f535cd543cc258f" alt="">
  107. <div class="zap-scanning__bottom">
  108. <img class="zap-scanning__icon" src="../assets/images/icon_scanning.png" alt="">
  109. <div class="zap-scanning__text">打开<span class="zap-scanning__color">微信</span>扫码登录</div>
  110. </div>
  111. <el-form-item>
  112. <div class="zap-agreement" style="padding-top: 52px;padding-left: 60px;">
  113. <span class="zap-agreement__text">登录视为同意并遵守</span>
  114. <div class="zap-agreement__link">
  115. <span>《招采云链服务平台会员注册协议》</span>
  116. <span>《招采云链服务平台隐私政策》</span>
  117. </div>
  118. </div>
  119. </el-form-item>
  120. </div>
  121. </el-form>
  122. <!-- 底部 -->
  123. </div>
  124. </el-main>
  125. <el-dialog
  126. title="选择企业"
  127. :visible.sync="dialogVisible"
  128. width="30%">
  129. <el-select v-model="chooseCompanyId" placeholder="请选择">
  130. <el-option
  131. v-for="item in companyList"
  132. :key="item.scyId"
  133. :label="item.scyName"
  134. :value="item.scyId">
  135. </el-option>
  136. </el-select>
  137. <span slot="footer" class="dialog-footer">
  138. <el-button type="primary" @click="chooseLogin()">确 定</el-button>
  139. </span>
  140. </el-dialog>
  141. </el-container>
  142. <el-footer></el-footer>
  143. </div>
  144. </template>
  145. <script>
  146. import { getCodeImg, sendShortMessage, chooseCompanyLogin} from "@/api/login";
  147. import { wxImg } from "@/api/system/weChat";
  148. import Cookies from "js-cookie";
  149. import { encrypt, decrypt } from "@/utils/jsencrypt";
  150. export default {
  151. name: "Login",
  152. data() {
  153. return {
  154. //默认背景图
  155. activeName: "login_password",
  156. baseImg: require('../assets/images/login_img.png'),
  157. BackgroundImg : require('../assets/images/login_img.png'),
  158. scanningLogin: false, // 是否扫码登陆
  159. logo: '',
  160. // baseLogo: require('../assets/images/lgo.png'),
  161. codeUrl: "",
  162. cookiePassword: "",
  163. loginForm: {
  164. shortMessageCode: '',
  165. username: "",
  166. password: "",
  167. rememberMe: false,
  168. code: "",
  169. uuid: "",
  170. },
  171. codeBtnWord: '获取验证码', // 获取验证码按钮文字
  172. waitTime:2, // 获取验证码按钮失效时间
  173. loginRules: {
  174. username: [
  175. {
  176. required: true,
  177. trigger: "blur",
  178. message: "用户名不能为空",
  179. },
  180. ],
  181. code: [
  182. {
  183. required: true,
  184. trigger: "change",
  185. message: "验证码不能为空",
  186. },
  187. ]
  188. },
  189. loading: false,
  190. redirect: undefined,
  191. wxSrc: require("../assets/images/wx1.png"),
  192. sendShortMessageBtn : false,
  193. dialogVisible : false,
  194. companyList : [],
  195. chooseCompanyId : ''
  196. };
  197. },
  198. watch: {
  199. $route: {
  200. handler: function (route) {
  201. this.redirect = route.query && route.query.redirect;
  202. },
  203. immediate: true,
  204. },
  205. },
  206. created() {
  207. this.getCode();
  208. this.getCookie();
  209. // this.getlistDomain();
  210. },
  211. methods: {
  212. changeImg(){
  213. this.wxSrc = require("../assets/images/wx.png")
  214. },
  215. returnImg(){
  216. this.wxSrc = require("../assets/images/wx1.png")
  217. },
  218. getCode() {
  219. getCodeImg().then((res) => {
  220. this.codeUrl = "data:image/gif;base64," + res.img;
  221. this.loginForm.uuid = res.uuid;
  222. });
  223. },
  224. getCookie() {
  225. const username = Cookies.get("username");
  226. const password = Cookies.get("password");
  227. const rememberMe = Cookies.get("rememberMe");
  228. this.loginForm = {
  229. username:
  230. username === undefined ? this.loginForm.username : username,
  231. password:
  232. password === undefined
  233. ? this.loginForm.password
  234. : decrypt(password),
  235. rememberMe:
  236. rememberMe === undefined ? false : Boolean(rememberMe),
  237. };
  238. },
  239. handleLogin() {
  240. this.$refs.loginForm.validate((valid) => {
  241. if (valid) {
  242. this.loading = true;
  243. // 密码登陆
  244. if (this.activeName == "login_password") {
  245. this.loginForm.type = "0";
  246. // 密码不能为空
  247. if (this.loginForm.password == null || this.loginForm.password == "") {
  248. this.msgError("请输入密码!");
  249. this.loading = false;
  250. return;
  251. }
  252. // 短信验证码登陆
  253. } else{
  254. this.loginForm.type = "1";
  255. // 密码不能为空
  256. if (this.loginForm.shortMessageCode == null || this.loginForm.shortMessageCode == "") {
  257. this.msgError("请输入短信验证码!");
  258. this.loading = false;
  259. return;
  260. }
  261. }
  262. if (this.loginForm.rememberMe) {
  263. Cookies.set("username", this.loginForm.username, {
  264. expires: 30,
  265. });
  266. Cookies.set(
  267. "password",
  268. encrypt(this.loginForm.password),
  269. { expires: 30 }
  270. );
  271. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  272. expires: 30,
  273. });
  274. } else {
  275. Cookies.remove("username");
  276. Cookies.remove("password");
  277. Cookies.remove("rememberMe");
  278. }
  279. this.$store
  280. .dispatch("Login", this.loginForm)
  281. .then((data) => {
  282. console.log(data)
  283. if (data.code == "0") {
  284. console.log("未认证!")
  285. this.$router.push({ path: "/certification" });
  286. // 认证单个企业
  287. } else if (data.code == "1") {
  288. // 认证通过
  289. if (data.loginUser.sysUser.companyStatus == "00") {
  290. console.log(this.redirect,"AAAAA")
  291. if(this.redirect == '/home'){
  292. this.$router.push({ path: "/homePage"+this.redirect || "/" });
  293. }else{
  294. this.$router.push({ path: this.redirect || "/" });
  295. }
  296. // this.$router.push({ path: this.redirect || "/" });
  297. // 认证未通过
  298. } else {
  299. console.log("未认证通过!")
  300. this.$router.push({ path: "/certification" });
  301. }
  302. // 多加企业
  303. } else {
  304. this.companyList = data.companyList;
  305. this.chooseCompanyId = this.companyList[0].scyId;
  306. this.dialogVisible = true;
  307. }
  308. this.loading = false;
  309. })
  310. .catch(() => {
  311. this.loading = false;
  312. this.getCode();
  313. });
  314. }
  315. });
  316. },
  317. getUrlKey(name) {
  318. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  319. },
  320. getWeChatImg(){
  321. wxImg().then((res) => {
  322. // console.log(res)
  323. location.href = res
  324. })
  325. },
  326. changeLoginType(e){
  327. this.getCode();
  328. },
  329. sendMessage(){
  330. this.$refs.loginForm.validate((valid) => {
  331. if (valid) {
  332. // 调用获取短信验证码接口
  333. sendShortMessage(this.loginForm.username, this.loginForm.code, this.loginForm.uuid).then(response => {
  334. this.sendShortMessageBtn = true;
  335. this.msgSuccess("发送成功!");
  336. // 因为下面用到了定时器,需要保存this指向
  337. let that = this
  338. that.waitTime = 60;
  339. this.codeBtnWord = `${this.waitTime}s 后重新获取`
  340. let timer = setInterval(function(){
  341. if(that.waitTime>1){
  342. that.waitTime--
  343. that.codeBtnWord = `${that.waitTime}s 后重新获取`
  344. }else{
  345. clearInterval(timer)
  346. that.codeBtnWord = '获取验证码'
  347. that.waitTime = 60
  348. that.getCode();
  349. that.sendShortMessageBtn = false;
  350. }
  351. },1000)
  352. }).catch((response)=>{
  353. this.getCode();
  354. });
  355. }
  356. })
  357. },
  358. chooseLogin(){
  359. chooseCompanyLogin(this.chooseCompanyId).then(response => {
  360. if (response.code == "200") {
  361. // 认证通过
  362. if (response.data.sysUser.companyStatus == "00") {
  363. if(this.redirect == '/home'){
  364. this.$router.push({ path: "/homePage"+this.redirect || "/" });
  365. }else{
  366. this.$router.push({ path: this.redirect || "/" });
  367. }
  368. // this.$router.push({ path: this.redirect || "/" });
  369. // 认证未通过
  370. } else {
  371. console.log("未认证通过!")
  372. this.$router.push({ path: "/certification" });
  373. }
  374. }
  375. }).catch((response)=>{
  376. });
  377. }
  378. },
  379. };
  380. </script>
  381. <style rel="stylesheet/scss" lang="scss">
  382. .login {
  383. display: flex;
  384. justify-content: center;
  385. align-items: center;
  386. height: 100%;
  387. background-size: cover;
  388. }
  389. // 中间背景图
  390. .login-form {
  391. margin-left: 75px;
  392. border-radius: 6px;
  393. background-size: 935px 434px;
  394. background-repeat: no-repeat;
  395. margin-top: 40px;
  396. // 输入框大小
  397. .el-input {
  398. height: 55px;
  399. width: 100%;
  400. background-image: linear-gradient(
  401. #fdfdfd,
  402. #fdfdfd),
  403. linear-gradient(
  404. #e7f0ff,
  405. #e7f0ff);
  406. background-blend-mode: normal,
  407. normal;
  408. input {
  409. height: 55px;
  410. width: 100%;
  411. font-size: 18px;
  412. }
  413. }
  414. .input-icon {
  415. height: 53px;
  416. width: 22px;
  417. margin-left: 14px;
  418. margin-right: 14px
  419. }
  420. .el-input--prefix .el-input__inner{
  421. padding-left: 50px;
  422. }
  423. }
  424. .login-tip {
  425. font-size: 13px;
  426. text-align: center;
  427. }
  428. .el-form-item--medium .el-form-item__content{
  429. display: flex;
  430. align-items: center;
  431. }
  432. // 验证码
  433. .login-code {
  434. height: 55px;
  435. img {
  436. cursor: pointer;
  437. vertical-align: middle;
  438. }
  439. }
  440. .login-code-img {
  441. flex: 1;
  442. height: 55px;
  443. margin-left: 8px;
  444. }
  445. // 大背景图
  446. .backdrop {
  447. padding-top: 100px;
  448. background-color: #ebf3ff;
  449. width: 100%;
  450. min-height: 100%;
  451. text-align: center;
  452. }
  453. .rightulliimg{
  454. width: 860px;
  455. }
  456. .divider_left{
  457. margin-left: -40px;
  458. }.el-button.disabled-style {
  459. background-color: #EEEEEE;
  460. color: #CCCCCC;
  461. }
  462. // 内部供应链
  463. .zap-tabs{
  464. width: 410px;
  465. height: 550px;
  466. padding: 10px 48px 46px;
  467. box-sizing: border-box;
  468. background-image: linear-gradient(
  469. #ffffff,
  470. #ffffff),
  471. linear-gradient(
  472. #f3f3f3,
  473. #f3f3f3);
  474. .el-tabs__nav-wrap{
  475. padding: 0 12px;
  476. }
  477. .el-tabs__nav-wrap::after{
  478. height: 0;
  479. }
  480. .el-tabs__nav{
  481. width: 100%;
  482. }
  483. .el-tabs__item{
  484. height: 56px;
  485. line-height: 56px;
  486. font-size: 24px;
  487. color: #333333;
  488. &:nth-of-type(3){
  489. padding-left: 30px;
  490. }
  491. }
  492. .el-tabs__item.is-active{
  493. color: #0056eb;
  494. }
  495. .el-tabs__active-bar{
  496. background-color: #0056eb;
  497. }
  498. }
  499. .login-left{
  500. width: 704px;
  501. .login-name{
  502. width: 100%;
  503. }
  504. .login-illustration{
  505. width: 515px;
  506. }
  507. }
  508. .zap-logo{
  509. position: absolute;
  510. top: 25px;
  511. left: 45px;
  512. width: 210px;
  513. height: 60px;
  514. }
  515. .zap-2dcode{
  516. display: flex;
  517. justify-content: flex-end;
  518. align-items: center;
  519. padding-top: 10px;
  520. padding-right: 10px;
  521. font-size: 0;
  522. background-color: #ffffff;
  523. }
  524. .zap-2dcode__text{
  525. width: 113px;
  526. height: 28px;
  527. }
  528. .zap-2dcode__img{
  529. width: 60px;
  530. height: 61px;
  531. cursor: pointer;
  532. }
  533. .zap-button{
  534. margin-top: 25px;
  535. width: 100%;
  536. height: 55px;
  537. font-size: 18px;
  538. border-radius: 0;
  539. background-image: linear-gradient(
  540. #0056eb,
  541. #0056eb),
  542. linear-gradient(
  543. #e7f0ff,
  544. #e7f0ff);
  545. background-blend-mode: normal,
  546. normal;
  547. }
  548. .zap-agreement{
  549. display: flex;
  550. align-items: top;
  551. margin-top: 8px;
  552. line-height: 18px;
  553. font-size: 12px;
  554. }
  555. .zap-agreement__text{
  556. color: #666666;
  557. }
  558. .zap-agreement__link{
  559. display: flex;
  560. flex-direction: column;
  561. align-items: flex-start;
  562. color: #389cf4;
  563. cursor: pointer;
  564. }
  565. .zap-code-button{
  566. padding: 0 16px;
  567. line-height: 55px;
  568. font-size: 18px;
  569. color: #23b24b;
  570. border: none;
  571. background-color: transparent;
  572. }
  573. .el-button.is-disabled, .el-button.is-disabled:hover, .el-button.is-disabled:focus{
  574. background-color: transparent;
  575. }
  576. // 扫码登录
  577. .zap-scanning{
  578. width: 410px;
  579. height: 550px;
  580. background-image: linear-gradient(
  581. #ffffff,
  582. #ffffff),
  583. linear-gradient(
  584. #f3f3f3,
  585. #f3f3f3);
  586. background-blend-mode: normal,
  587. normal;
  588. box-sizing: border-box;
  589. }
  590. .zap-scanning__title{
  591. padding: 0 60px;
  592. font-size: 24px;
  593. color: #333333;
  594. }
  595. .zap-scanning__img{
  596. display: block;
  597. width: 220px;
  598. height: 220px;
  599. margin: 40px auto 0;
  600. object-fit: cover;
  601. }
  602. .zap-scanning__bottom{
  603. display: flex;
  604. align-items: center;
  605. justify-content: center;
  606. margin-top: 18px;
  607. font-size: 14px;
  608. }
  609. .zap-scanning__icon{
  610. width: 22px;
  611. height: 22px;
  612. margin-right: 10px;
  613. }
  614. .zap-scanning__text{
  615. color: #333333;
  616. }
  617. .zap-scanning__color{
  618. color: #23b24b;
  619. }
  620. </style>