index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="boot">
  3. <Swipe class="boot__guide" :loop="false" v-if="state.showGuide">
  4. <SwipeItem>
  5. <img src="@mobile/assets/images/boot-1080p.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(onLoad)" />
  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 { showLoading, dialog } from '@/utils/vant'
  21. import { useLogin } from '@/business/login'
  22. import service from '@/services'
  23. import plus from '@/utils/h5plus'
  24. const { logining, initBaseData } = useLogin()
  25. const route = useRoute()
  26. const router = useRouter()
  27. const onLoad = initBaseData(true) // 初始化数据
  28. const countdown = 1 // 倒计时秒数
  29. const state = reactive({
  30. showGuide: localStorage.getItem('thj_app_showguide') === 'false' ? false : true, // 是否显示引导页
  31. second: countdown, // 剩余秒数
  32. currentRate: 100, // 当前进度
  33. rate: 100, // 目标进度
  34. })
  35. // 倒计时
  36. const timer = window.setInterval(() => {
  37. state.second--
  38. state.rate = (100 / countdown) * state.second
  39. if (state.second <= 0) {
  40. clearInterval(timer)
  41. // 判断是否首次打开应用
  42. if (!state.showGuide) {
  43. skip(onLoad)
  44. }
  45. }
  46. }, 1000)
  47. // 跳过广告
  48. const skip = (promise: Promise<void>) => {
  49. clearInterval(timer)
  50. const toast = logining.value ? showLoading() : undefined
  51. promise.then(() => {
  52. plus.exitFullSreen()
  53. localStorage.setItem('thj_app_showguide', 'false')
  54. const redirect = route.query.redirect
  55. if (redirect) {
  56. router.replace(redirect.toString())
  57. } else {
  58. router.replace({ name: 'Home' })
  59. }
  60. }).catch(() => {
  61. if (service.isReady) {
  62. router.replace({ name: 'Home' })
  63. } else {
  64. tryInit()
  65. }
  66. }).finally(() => {
  67. toast?.close()
  68. })
  69. }
  70. // 初始化失败重试
  71. const tryInit = () => {
  72. dialog({
  73. message: '加载失败,请稍后再试',
  74. showCancelButton: plus.hasPlus(),
  75. cancelButtonText: '退出',
  76. confirmButtonText: '重试'
  77. }).then(() => {
  78. skip(initBaseData(true))
  79. }).catch(() => {
  80. plus.quit()
  81. })
  82. }
  83. plus.setFullSreen()
  84. </script>
  85. <style lang="less" scoped>
  86. @import './index.less';
  87. </style>