index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="boot">
  3. <Swipe class="boot__guide" :loop="false" v-if="guidePage">
  4. <SwipeItem>
  5. <img src="@mobile/assets/images/boot-720p.png" />
  6. </SwipeItem>
  7. <SwipeItem>
  8. <img src="@mobile/assets/images/guide-1.png" />
  9. </SwipeItem>
  10. <SwipeItem>
  11. <img src="@mobile/assets/images/guide-2.png" @click="skip" />
  12. </SwipeItem>
  13. </Swipe>
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. import { reactive } from 'vue'
  18. import { useRoute, useRouter } from 'vue-router'
  19. import { Swipe, SwipeItem } from 'vant'
  20. import { initBaseData } from '@/business/common'
  21. import service from '@/services'
  22. import socket from '@/services/socket'
  23. import plus from '@/utils/h5plus'
  24. const route = useRoute()
  25. const router = useRouter()
  26. const guidePage = localStorage.getItem('thj_app_guide') === 'false' ? false : true // 是否显示引导页
  27. const countdown = 1 // 倒计时秒数
  28. const state = reactive({
  29. loading: true,
  30. second: countdown, // 剩余秒数
  31. currentRate: 100, // 当前进度
  32. rate: 100, // 目标进度
  33. })
  34. // 倒计时
  35. const timer = window.setInterval(() => {
  36. state.second--
  37. state.rate = (100 / countdown) * state.second
  38. if (state.second <= 0) {
  39. // 判断是否首次打开应用
  40. if (guidePage) {
  41. localStorage.setItem('thj_app_guide', 'false')
  42. } else {
  43. skip()
  44. }
  45. }
  46. }, 1000)
  47. // 跳过广告
  48. const skip = () => {
  49. clearInterval(timer)
  50. plus.exitFullSreen()
  51. // 判断服务是否初始化完成
  52. if (state.loading) {
  53. router.replace('/user/login')
  54. } else {
  55. const redirect = route.query.redirect
  56. if (redirect) {
  57. router.replace(redirect.toString())
  58. } else {
  59. router.replace('/')
  60. }
  61. }
  62. }
  63. plus.setFullSreen()
  64. // 等待服务初始化
  65. service.onReady().then(async () => {
  66. // 等待连接交易服务
  67. await socket.connectTrade()
  68. // 等待业务数据初始化
  69. await initBaseData()
  70. state.loading = false
  71. })
  72. </script>
  73. <style lang="less" scoped>
  74. @import './index.less';
  75. </style>