App.ku.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. import { useTokenStore } from '@/store/token'
  4. import FgTabbar from '@/tabbar/index.vue'
  5. import { useLoadingStore } from './store/loading'
  6. import { isPageTabbar, tabbarStore } from './tabbar/store'
  7. import { currRoute } from './utils'
  8. const isCurrentPageTabbar = ref(true)
  9. const loadingStore = useLoadingStore()
  10. const tokenStore = useTokenStore()
  11. onShow(() => {
  12. console.log('App.ku.vue onShow', currRoute())
  13. const { path, query } = currRoute()
  14. // “蜡笔小开心”提到本地是 '/pages/index/index',线上是 '/' 导致线上 tabbar 不见了
  15. // 所以这里需要判断一下,如果是 '/' 就当做首页,也要显示 tabbar
  16. isCurrentPageTabbar.value = path === '/' || isPageTabbar(path)
  17. setTimeout(() => {
  18. if (isCurrentPageTabbar.value) {
  19. tabbarStore.setAutoCurIdx(path)
  20. }
  21. }, 0)
  22. // 判断是否是通过分享进入
  23. const paramKey = 'CCShareId'
  24. const keyName = 'shareRecordId'
  25. // 券中心小程序码变更,参数需从scene中获取
  26. function getSceneData(paramsQuery) {
  27. const temp = {}
  28. if (paramsQuery?.scene) {
  29. const sceneData = decodeURIComponent(paramsQuery.scene)
  30. const [key, value] = sceneData.split('=')
  31. if (key === paramKey) {
  32. temp[keyName] = value
  33. }
  34. console.log(temp)
  35. return temp
  36. }
  37. return temp
  38. }
  39. const queryParams = getSceneData(query)
  40. if (!!queryParams && Object.keys(queryParams).includes(keyName)) {
  41. tokenStore.cacheShareParams(queryParams)
  42. }
  43. loadingStore.hideLoading()
  44. })
  45. const exposeRef = ref('this is form app.Ku.vue')
  46. defineExpose({
  47. exposeRef,
  48. })
  49. </script>
  50. <template>
  51. <view>
  52. <!-- 这个先隐藏了,知道这样用就行 -->
  53. <!-- <view class="hidden text-center">
  54. {{ helloKuRoot }},这里可以配置全局的东西
  55. </view> -->
  56. <up-no-network />
  57. <KuRootView />
  58. <up-loading-page :loading="loadingStore.isLoading" z-index="1000" size="50" />
  59. <FgTabbar v-if="isCurrentPageTabbar" />
  60. </view>
  61. </template>