index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <script>
  2. import Vue from 'vue'
  3. import countryCode from '@/lib/countryCode.json'
  4. import thirdLogin from './third-login.vue'
  5. import { sendSmsCode, sentEmailCode, register, confirmEmail, getGoogleStatus, getLinkedinStatus } from '@/api/user'
  6. export default Vue.extend({
  7. name: 'Index',
  8. components: {
  9. thirdLogin
  10. },
  11. data() {
  12. return {
  13. countryCode,
  14. username: '',
  15. password: '',
  16. confirmPassword: '',
  17. confirmCode: '',
  18. savePassword: false,
  19. loading: false,
  20. isLogin: true,
  21. isPhone: true,
  22. phone: '',
  23. country_code: '86',
  24. email: '',
  25. code: '',
  26. timer: null,
  27. count: 0,
  28. pre_register_key: '',
  29. third_login: '',
  30. third_token: '',
  31. need_bind: false,
  32. is_back: false,
  33. env: process.env.NODE_ENV
  34. }
  35. },
  36. mounted() {
  37. this.getSavedAccount()
  38. this.parseQuery()
  39. },
  40. methods: {
  41. parseQuery() {
  42. const url = new URL(window.location.href.replace('#', '?'))
  43. function showError() {
  44. this.$notify({
  45. title: '登录失败',
  46. message: '登录失败,请稍后重试。',
  47. type: 'error'
  48. })
  49. this.third_login = ''
  50. this.is_back = false
  51. }
  52. if (url.searchParams.get('code')) {
  53. this.is_back = true
  54. this.third_login = 'linkin'
  55. getLinkedinStatus(
  56. url.searchParams.get('state'),
  57. url.searchParams.get('code')
  58. ).then(res => {
  59. if (res.data.api_token) {
  60. this.tokenLogin(res.data.api_token)
  61. } else if (res.data.third_token) {
  62. this.third_token = res.data.third_token
  63. this.need_bind = true
  64. } else {
  65. showError()
  66. }
  67. }).catch(err => {
  68. this.$notify({
  69. title: '提示',
  70. message: '领英授权登录失败' + err,
  71. type: 'error'
  72. })
  73. showError()
  74. })
  75. }
  76. if (url.searchParams.get('access_token')) {
  77. this.is_back = true
  78. this.third_login = 'google'
  79. getGoogleStatus(
  80. url.searchParams.get('state'),
  81. url.searchParams.get('access_token')
  82. ).then(res => {
  83. if (res.data.api_token) {
  84. this.tokenLogin(res.data.api_token)
  85. } else if (res.data.third_token) {
  86. this.third_token = res.data.third_token
  87. this.need_bind = true
  88. } else {
  89. showError()
  90. }
  91. }).catch(err => {
  92. this.$notify({
  93. title: '提示',
  94. message: '谷歌授权登录失败' + err,
  95. type: 'error'
  96. })
  97. showError()
  98. })
  99. }
  100. },
  101. openThirdLogin(type) {
  102. this.is_back = false
  103. this.third_login = type
  104. },
  105. closeThirdLogin() {
  106. this.is_back = false
  107. this.need_bind = false
  108. this.third_login = ''
  109. this.third_token = ''
  110. },
  111. sentSMSCode() {
  112. if (this.loading || this.timer) {
  113. return
  114. }
  115. this.loading = true
  116. sendSmsCode(this.phone, this.country_code).then(res => {
  117. this.$notify({
  118. title: '发送成功',
  119. message: '短信验证码已发送,请注意查收',
  120. type: 'success'
  121. })
  122. this.count = 60
  123. this.timer = setInterval(() => {
  124. if (this.count > 0) {
  125. this.count--
  126. } else {
  127. clearInterval(this.timer)
  128. this.timer = null
  129. }
  130. }, 1000)
  131. this.loading = false
  132. }).catch(err => {
  133. this.$notify({
  134. title: '提示',
  135. message: '验证码发送失败' + err,
  136. type: 'error'
  137. })
  138. this.loading = false
  139. })
  140. },
  141. sentMailCode() {
  142. if (this.loading || this.timer) {
  143. return
  144. }
  145. this.loading = true
  146. sentEmailCode(this.email).then(res => {
  147. this.$notify({
  148. title: '发送成功',
  149. message: '邮件已发送,请注意查收',
  150. type: 'success'
  151. })
  152. this.count = 60
  153. this.timer = setInterval(() => {
  154. if (this.count > 0) {
  155. this.count--
  156. } else {
  157. clearInterval(this.timer)
  158. this.timer = null
  159. }
  160. }, 1000)
  161. this.loading = false
  162. }).catch(err => {
  163. this.$notify({
  164. title: '发送失败',
  165. message: '验证码发送失败' + err,
  166. type: 'error'
  167. })
  168. this.loading = false
  169. })
  170. },
  171. emailRegister() {
  172. if (this.loading) {
  173. return
  174. }
  175. if (this.email === '' || this.code === '' || this.password === '' || this.confirmPassword === '') {
  176. this.$notify({
  177. title: '提示',
  178. message: '请填写邮箱和验证码!',
  179. type: 'warning'
  180. })
  181. }
  182. if (this.password !== this.confirmPassword) {
  183. this.$notify({
  184. title: '提示',
  185. message: '密码不一致!',
  186. type: 'warning'
  187. })
  188. }
  189. this.loading = true
  190. let invite_code = localStorage.getItem('duoguo_invite_code') || ''
  191. register(this.email, '', this.code, 1, 0, invite_code).then(res => {
  192. this.pre_register_key = res.data.pre_register_key
  193. confirmEmail(this.pre_register_key, this.password, this.confirmPassword).then(res => {
  194. this.isLogin = true
  195. this.$notify({
  196. title: '注册成功',
  197. message: '即将跳转至登录页。',
  198. type: 'success'
  199. })
  200. }).catch(err => {
  201. this.$notify({
  202. title: '注册失败',
  203. message: err,
  204. type: 'error'
  205. })
  206. this.loading = false
  207. })
  208. }).catch(err => {
  209. this.$notify({
  210. title: '注册失败',
  211. message: err,
  212. type: 'error'
  213. })
  214. this.loading = false
  215. })
  216. },
  217. phoneRegister() {
  218. if (this.loading) {
  219. return
  220. }
  221. if (this.phone === '' || this.code === '') {
  222. this.$notify({
  223. title: '提示',
  224. message: '请填写电话号码和验证码!',
  225. type: 'warning'
  226. })
  227. return
  228. }
  229. let invite_code = localStorage.getItem('duoguo_invite_code') || ''
  230. register(this.phone, this.country_code, this.code, 0, 0, invite_code).then(res => {
  231. this.isLogin = true
  232. this.$notify({
  233. title: '注册成功',
  234. message: '即将跳转至登录页。',
  235. type: 'success'
  236. })
  237. }).catch(err => {
  238. this.$notify({
  239. title: '注册失败',
  240. message: err,
  241. type: 'error'
  242. })
  243. })
  244. },
  245. getSavedAccount() {
  246. const account = localStorage.getItem('savedAccount')
  247. if (this.$route.query.inviteCode) {
  248. localStorage.setItem('duoguo_invite_code', this.$route.query.inviteCode)
  249. }
  250. if (account) {
  251. this.username = account.username
  252. this.password = account.password
  253. this.savePassword = true
  254. }
  255. },
  256. tokenLogin(token) {
  257. this.$store.dispatch('tokenLogin', { token: token }).then(res => {
  258. this.$router.push('/dashboard')
  259. }).catch(err => {
  260. this.$notify({
  261. title: '提示',
  262. message: '使用本地令牌登录失败' + err,
  263. type: 'error'
  264. })
  265. this.$message.error(err.message)
  266. })
  267. },
  268. login() {
  269. if (!this.username) {
  270. this.$message.error('请输入用户名')
  271. return
  272. }
  273. if (!this.password) {
  274. this.$message.error('请输入密码')
  275. return
  276. }
  277. if (this.loading) {
  278. return
  279. }
  280. this.loading = true
  281. this.$store.dispatch('login', {
  282. username: this.username,
  283. password: this.password,
  284. login_type: 0,
  285. login_portal: 0,
  286. savePassword: this.savePassword
  287. }).then(res => {
  288. this.loading = false
  289. this.$router.push('/dashboard')
  290. }).catch(err => {
  291. this.$notify({
  292. title: '提示',
  293. message: '登录失败' + err,
  294. type: 'error'
  295. })
  296. this.loading = false
  297. this.$message.error(err.message)
  298. })
  299. }
  300. }
  301. })
  302. </script>
  303. <template>
  304. <div class="body">
  305. <div class="footer">
  306. <div class="item">
  307. <span>Copyright © 2025 厦门聚页创意科技有限公司 Xiamen Matchpages Technology Co., Ltd All rights Reserved</span>
  308. </div>
  309. <a class="item" href="https://beian.miit.gov.cn/" target="_blank">
  310. <span>闽ICP备1145141919号</span>
  311. </a>
  312. <a class="item" href="https://beian.miit.gov.cn/" target="_blank">
  313. <img class="gongan" src="/static/image/beian.png" alt="">
  314. <span>闽公网安备1145141919号</span>
  315. </a>
  316. </div>
  317. <div class="bg-cont">
  318. <div class="text-cont">
  319. <img src="/static/image/logo_big_white.png" class="logo">
  320. <div class="title">10分钟创建海外观众预登记服务平台</div>
  321. <div class="desc">展会活动观众预登记的数字展会工具</div>
  322. </div>
  323. <img class="bg-image" src="/static/image/login2.webp" alt="">
  324. </div>
  325. <div :style="{height:third_login?'64vh':'auto'}" class="login-cont">
  326. <!-- <div class="image-left">-->
  327. <!-- <img class="image" src="/static/image/login.webp" alt="">-->
  328. <!-- <div class="title">展会服务系统</div>-->
  329. <!-- </div>-->
  330. <div class="cont-right">
  331. <div class="title">
  332. <div :class="['item',isLogin?'active':'']" @click="isLogin=true">登录</div>
  333. <div :class="['item',isLogin?'':'active']" @click="isLogin=false">注册</div>
  334. </div>
  335. <template v-if="isLogin">
  336. <el-input v-model="username" prefix-icon="el-icon-user" placeholder="请输入用户名" class="input" />
  337. <el-input v-model="password" prefix-icon="el-icon-unlock" placeholder="请输入密码" show-password class="input" />
  338. <el-checkbox v-model="savePassword">记住密码</el-checkbox>
  339. <el-button type="primary" class="button" @click="login">
  340. <span>登录</span>
  341. <span v-if="loading" class="el-icon-loading" />
  342. </el-button>
  343. </template>
  344. <template v-else>
  345. <template v-if="isPhone">
  346. <el-select v-model="country_code" placeholder="请选择国家">
  347. <el-option v-for="(item,index) in countryCode" :key="item.country_code+index" :label="'+'+item.phone_code+'('+item.chinese_name+')'" :value="item.phone_code" />
  348. </el-select>
  349. <el-input v-model="phone" prefix-icon="el-icon-mobile-phone" placeholder="请输入手机号码" class="input" />
  350. <el-input v-model="code" prefix-icon="el-icon-key" placeholder="请输入验证码" class="input">
  351. <el-button slot="append" :disabled="!!timer" :loading="loading" @click="sentSMSCode()">{{ timer?count+'s':'发送验证码' }}</el-button>
  352. </el-input>
  353. <div class="change-way" @click="isPhone=false">使用邮箱注册</div>
  354. <el-button type="primary" class="button" @click="phoneRegister()">
  355. <span>注册</span>
  356. <span v-if="loading" class="el-icon-loading" />
  357. </el-button>
  358. </template>
  359. <template v-else>
  360. <el-input v-model="email" prefix-icon="el-icon-message" placeholder="请输入电子邮箱地址" class="input" />
  361. <el-input v-model="code" prefix-icon="el-icon-key" placeholder="请输入验证码" class="input">
  362. <el-button slot="append" :disabled="!!timer" :loading="loading" @click="sentMailCode()">{{ timer?count+'s':'发送验证码' }}</el-button>
  363. </el-input>
  364. <el-input v-model="password" prefix-icon="el-icon-unlock" placeholder="请输入密码" show-password class="input" />
  365. <el-input v-model="confirmPassword" prefix-icon="el-icon-unlock" placeholder="请再次输入密码" show-password class="input" />
  366. <div class="change-way" @click="isPhone=true">使用手机注册</div>
  367. <el-button type="primary" class="button" @click="emailRegister()">
  368. <span>注册</span>
  369. <span v-if="loading" class="el-icon-loading" />
  370. </el-button>
  371. </template>
  372. </template>
  373. <div class="third-login">
  374. <div class="third-title">第三方登录/注册:</div>
  375. <div class="button-list">
  376. <div class="third-button wechat" @click="openThirdLogin('wechat')">
  377. <img class="icon" src="/static/image/icon/wechat.png">
  378. </div>
  379. <div class="third-button google" @click="openThirdLogin('google')">
  380. <img class="icon" src="/static/image/icon/google.png">
  381. </div>
  382. <div class="third-button linkin" @click="openThirdLogin('linkin')">
  383. <img class="icon" src="/static/image/icon/linkin.png">
  384. </div>
  385. </div>
  386. </div>
  387. <div :class="['third-window',third_login?'active':'']">
  388. <div class="third-head">
  389. <span class="third-title">第三方登录</span>
  390. <span class="el-icon-close" @click="closeThirdLogin()" />
  391. </div>
  392. <div class="third-body">
  393. <third-login
  394. v-if="third_login"
  395. :is_back="is_back"
  396. :need_bind.sync="need_bind"
  397. :third_token.sync="third_token"
  398. :login_type="third_login"
  399. @tokenLogin="tokenLogin"
  400. />
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. </div>
  406. </template>
  407. <style scoped lang="scss">
  408. .body{
  409. padding: 0 240px;
  410. width: 100%;
  411. height: 100%;
  412. display: flex;
  413. align-items: center;
  414. justify-content: flex-end;
  415. background-image: linear-gradient(120deg,#F7FAFF,#A6C5FE);
  416. .footer{
  417. z-index: 2;
  418. position: absolute;
  419. left: 0;
  420. gap: 12px;
  421. bottom: 16px;
  422. width: 100%;
  423. display: flex;
  424. justify-content: center;
  425. .item{
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. gap: 4px;
  430. font-size: 14px;
  431. color: grey;
  432. text-decoration: none;
  433. .gongan{
  434. height: 1.2em;
  435. }
  436. }
  437. }
  438. .bg-cont{
  439. position: absolute;
  440. left: 0;
  441. top: 0;
  442. width: 52%;
  443. height: 100%;
  444. .text-cont{
  445. position: absolute;
  446. left: 48px;
  447. top: 64px;
  448. color: #ffffff;
  449. .logo{
  450. height: 52px;
  451. }
  452. .title{
  453. margin-top: 50px;
  454. padding-left: 8px;
  455. border-left: 3px solid #ffffff;
  456. font-size: 36px;
  457. font-weight: bold;
  458. }
  459. .desc{
  460. font-size: 20px;
  461. margin-top: 16px;
  462. }
  463. }
  464. .bg-image{
  465. width: 100%;
  466. }
  467. }
  468. .login-cont{
  469. background: white;
  470. overflow: hidden;
  471. display: grid;
  472. border-radius: 12px;
  473. box-shadow: 0 0 12px #00000011;
  474. grid-template-columns: 1fr;
  475. .image-left{
  476. display: none;
  477. padding: 40px;
  478. background: #123068;
  479. position: relative;
  480. .image{
  481. position: absolute;
  482. object-fit: cover;
  483. left: 0;
  484. top: 0;
  485. width: 100%;
  486. height: 100%;
  487. }
  488. .title{
  489. position: relative;
  490. color: white;
  491. font-size: 28px;
  492. font-weight: bold;
  493. }
  494. }
  495. .cont-right{
  496. position: relative;
  497. padding: 40px;
  498. display: flex;
  499. flex-direction: column;
  500. grid-gap: 16px;
  501. .third-window{
  502. position: absolute;
  503. top: 0;
  504. right: 0;
  505. width: 100%;
  506. height: 100%;
  507. background-color: white;
  508. transition-duration: 300ms;
  509. transform: translateX(100%);
  510. z-index: 10;
  511. display: grid;
  512. grid-template-rows: auto 1fr;
  513. &.active{
  514. transform: translateX(0);
  515. }
  516. .third-body{
  517. position: relative;
  518. iframe{
  519. border: none;
  520. width: 100%;
  521. height: 100%;
  522. }
  523. }
  524. .third-head{
  525. color: grey;
  526. padding: 8px;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. .third-title{
  531. padding-left: 8px;
  532. }
  533. .el-icon-close{
  534. border-radius: 8px;
  535. width: 32px;
  536. height: 32px;
  537. display: flex;
  538. align-items: center;
  539. justify-content: center;
  540. cursor: pointer;
  541. &:hover{
  542. background-color: #eeeeee;
  543. }
  544. }
  545. }
  546. }
  547. .third-login{
  548. padding-top: 16px;
  549. border-top: 1px solid #ececec;
  550. .third-title{
  551. font-size: 16px;
  552. color: grey;
  553. margin-bottom: 16px;
  554. }
  555. .button-list{
  556. display: flex;
  557. gap: 16px;
  558. .third-button{
  559. transition-duration: 300ms;
  560. cursor: pointer;
  561. width: 44px;
  562. height: 44px;
  563. border-radius: 50%;
  564. background-color: #eeeeee;
  565. display: flex;
  566. align-items: center;
  567. justify-content: center;
  568. .icon{
  569. transition-duration: 300ms;
  570. width: 22px;
  571. height: 22px;
  572. object-fit: contain;
  573. }
  574. &:hover{
  575. &.wechat{
  576. background-color: #0E932E;
  577. box-shadow: 0 0 0 1px white,0 0 0 3px #0E932E;
  578. }
  579. &.google{
  580. background-color: #EA4335;
  581. box-shadow: 0 0 0 1px white,0 0 0 3px #EA4335;
  582. }
  583. &.linkin{
  584. background-color: #0B66C1;
  585. box-shadow: 0 0 0 1px white,0 0 0 3px #0B66C1;
  586. }
  587. .icon{
  588. filter: brightness(0) invert(1)
  589. }
  590. }
  591. }
  592. }
  593. }
  594. .title{
  595. height: 36px;
  596. font-weight: bold;
  597. margin-bottom: 26px;
  598. display: flex;
  599. align-items: flex-end;
  600. gap: 20px;
  601. .item{
  602. line-height: 1.3;
  603. transition-duration: 300ms;
  604. font-size: 27px;
  605. cursor: pointer;
  606. display: flex;
  607. flex-direction: column;
  608. align-items: center;
  609. color: gray;
  610. &::after{
  611. transition-duration: 300ms;
  612. width: 40%;
  613. content: '';
  614. display: block;
  615. height: 4px;
  616. border-radius: 2px;
  617. background-color: lightgray;
  618. }
  619. &.active{
  620. font-size: 28px;
  621. color: black;
  622. &::after{
  623. width: 80%;
  624. background-color: #2563EB;
  625. }
  626. }
  627. }
  628. }
  629. .button{
  630. font-size: 18px;
  631. margin-top: 48px;
  632. width: 400px;
  633. }
  634. .test-button{
  635. margin-left: unset;
  636. font-size: 18px;
  637. width: 400px;
  638. }
  639. .input{
  640. font-size: 16px;
  641. width: 400px;
  642. }
  643. .change-way {
  644. font-weight: 500;
  645. line-height: 19px;
  646. font-size: 15px;
  647. color: #409EFF;
  648. cursor: pointer;
  649. width: fit-content;
  650. }
  651. }
  652. }
  653. }
  654. </style>