index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(init())" />
  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 countdown = 1 // 倒计时秒数
  28. const state = reactive({
  29. showGuide: (!plus.hasPlus() || localStorage.getItem('thj_app_showguide') === 'false') ? false : true, // 是否显示引导页
  30. second: countdown, // 剩余秒数
  31. currentRate: 100, // 当前进度
  32. rate: 100, // 目标进度
  33. })
  34. const init = () => initBaseData(true) // 初始化数据
  35. const onLoad = state.showGuide ? Promise.resolve() : init()
  36. // 倒计时
  37. const timer = window.setInterval(() => {
  38. state.second--
  39. state.rate = (100 / countdown) * state.second
  40. if (state.second <= 0) {
  41. clearInterval(timer)
  42. // 判断是否首次打开应用
  43. if (!state.showGuide) {
  44. skip(onLoad)
  45. }
  46. }
  47. }, 1000)
  48. // 跳过广告
  49. const skip = (promise: Promise<void>) => {
  50. clearInterval(timer)
  51. const toast = logining.value ? showLoading() : undefined
  52. promise.then(() => {
  53. plus.exitFullSreen()
  54. localStorage.setItem('thj_app_showguide', 'false')
  55. const redirect = route.query.redirect
  56. if (redirect) {
  57. router.replace(redirect.toString())
  58. } else {
  59. router.replace({ name: 'home-index' })
  60. }
  61. }).catch((err) => {
  62. if (service.isReady) {
  63. router.replace({ name: 'home-index' })
  64. } else {
  65. tryInit(err)
  66. }
  67. }).finally(() => {
  68. toast?.close()
  69. })
  70. }
  71. // 初始化失败重试
  72. const tryInit = (message: string) => {
  73. dialog({
  74. message,
  75. showCancelButton: plus.hasPlus(),
  76. cancelButtonText: '退出',
  77. confirmButtonText: '重试'
  78. }).then(() => {
  79. skip(init())
  80. }).catch(() => {
  81. plus.quit()
  82. })
  83. }
  84. plus.setFullSreen()
  85. </script>
  86. <style lang="less" scoped>
  87. @import './index.less';
  88. </style>