App.ku.vue 2.2 KB

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