App.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <script setup>
  2. import TabBar from './components/TabBar.vue'
  3. import { useRoute } from 'vue-router'
  4. import { computed, onMounted } from 'vue'
  5. import { useStore } from 'vuex'
  6. const route = useRoute()
  7. const store = useStore()
  8. // 计算是否显示TabBar
  9. const showTabBar = computed(() => {
  10. // 在加载页面不显示TabBar
  11. const paths = ['/loading', '/', '/exhibition', '/collection', '/user', '/indexPage']
  12. return paths.includes(route.path)
  13. })
  14. // 从store获取isFrom值
  15. const isFrom = computed(() => store.getters.getIsFrom)
  16. // 组件挂载时从URL参数获取isFrom并存储到store
  17. onMounted(() => {
  18. const hash = window.location.hash
  19. // 从hash中提取查询参数部分
  20. const queryIndex = hash.indexOf('?')
  21. if (queryIndex !== -1) {
  22. const queryString = hash.substring(queryIndex + 1)
  23. const urlParams = new URLSearchParams(queryString)
  24. const isFromParam = urlParams.get('isFrom')
  25. store.dispatch('setIsFrom', isFromParam)
  26. } else {
  27. console.log('No query parameters found', 9999)
  28. store.dispatch('setIsFrom', null)
  29. }
  30. })
  31. </script>
  32. <template>
  33. <RouterView :key="$route.fullPath" />
  34. <TabBar v-if="showTabBar && isFrom != 'weixin'" />
  35. </template>
  36. <style scoped>
  37. @media (min-width: 1024px) {
  38. body {
  39. display: flex;
  40. place-items: center;
  41. }
  42. }
  43. </style>