App.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-01-07 09:49:29
  4. * @LastEditTime: 2021-11-01 14:08:55
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \vue3-element-admin\src\App.vue
  8. -->
  9. <template>
  10. <!-- <router-view v-slot="{ Component }">
  11. <keep-alive exclude="GardenReport">
  12. <component :is="Component" />
  13. </keep-alive>
  14. </router-view> -->
  15. <router-view v-slot="{ Component }">
  16. <keep-alive v-if="route.meta && route.meta.keepAlive">
  17. <component :is="Component" />
  18. </keep-alive>
  19. <component v-else :is="Component" />
  20. </router-view>
  21. <Tabbar class="tabbar" route fixed v-show="showTab" active-color="#2199F8" inactive-color="#898989">
  22. <tabbar-item replace to="/home">
  23. <span>农场监测</span>
  24. <template #icon="props">
  25. <img
  26. :src="
  27. props.active
  28. ? require('@/assets/img/tab_bar/home-active.png')
  29. : require('@/assets/img/tab_bar/home.png')
  30. "
  31. />
  32. </template>
  33. </tabbar-item>
  34. <tabbar-item replace to="/plan">
  35. <span>农事方案</span>
  36. <template #icon="props">
  37. <img
  38. :src="
  39. props.active
  40. ? require('@/assets/img/tab_bar/farm-active.png')
  41. : require('@/assets/img/tab_bar/farm.png')
  42. "
  43. />
  44. </template>
  45. </tabbar-item>
  46. <tabbar-item replace to="/message">
  47. <span>农服农资</span>
  48. <template #icon="props">
  49. <img
  50. :src="
  51. props.active
  52. ? require('@/assets/img/tab_bar/service-active.png')
  53. : require('@/assets/img/tab_bar/service.png')
  54. "
  55. />
  56. </template>
  57. </tabbar-item>
  58. <tabbar-item replace to="/mine">
  59. <span>个人中心</span>
  60. <template #icon="props">
  61. <img
  62. :src="
  63. props.active
  64. ? require('@/assets/img/tab_bar/mine-active.png')
  65. : require('@/assets/img/tab_bar/mine.png')
  66. "
  67. />
  68. </template>
  69. </tabbar-item>
  70. </Tabbar>
  71. <!-- 开启底部安全区适配 -->
  72. <number-keyboard safe-area-inset-bottom />
  73. </template>
  74. <script setup>
  75. import { NumberKeyboard } from "vant";
  76. import { Tabbar, TabbarItem } from "vant";
  77. import { nextTick, watch, onMounted, ref } from "vue";
  78. import { useRoute, useRouter } from "vue-router";
  79. import { useStore } from "vuex";
  80. // import {NH,NF,NZ,EXPERT} from "@/common/user_role";
  81. const store = useStore();
  82. const route = useRoute();
  83. const router = useRouter();
  84. // 首页loading加载完才显示底部导航栏
  85. const showTab = ref(false);
  86. let tabBarHeight = 0;
  87. onMounted(() => {
  88. setTimeout(() => {
  89. if (route.meta.showTabbar) {
  90. showTab.value = true;
  91. }
  92. nextTick(() => {
  93. const tabBarElement = document.querySelector(".van-tabbar");
  94. if (tabBarElement) {
  95. tabBarHeight = tabBarElement.offsetHeight;
  96. localStorage.setItem("tabBarHeight", tabBarHeight);
  97. store.commit("home/SET_TAB_BAR_HEIGHT", tabBarHeight);
  98. }
  99. });
  100. }, 500);
  101. });
  102. watch(
  103. () => route.name,
  104. (newName, oldName) => {
  105. // 在这里执行你的自定义逻辑
  106. showTab.value = false;
  107. if (route.meta.showTabbar) {
  108. showTab.value = true;
  109. }
  110. nextTick(() => {
  111. const tabBarElement = document.querySelector(".van-tabbar");
  112. if (tabBarElement) {
  113. tabBarHeight = tabBarElement.offsetHeight;
  114. localStorage.setItem("tabBarHeight", tabBarHeight);
  115. store.commit("home/SET_TAB_BAR_HEIGHT", tabBarHeight);
  116. }
  117. });
  118. },
  119. { immediate: false }
  120. );
  121. </script>
  122. <style lang="scss" scoped>
  123. .tabbar {
  124. position: fixed;
  125. pointer-events: all;
  126. z-index: 9999;
  127. }
  128. </style>