App.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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" v-if="curRole == 0">
  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. <!-- 专家 -->
  35. <tabbar-item replace to="/farm_manage" v-if="curRole == 1">
  36. <span>农场管理</span>
  37. <template #icon="props">
  38. <img
  39. :src="
  40. props.active
  41. ? require('@/assets/img/tab_bar/home-active.png')
  42. : require('@/assets/img/tab_bar/home.png')
  43. "
  44. />
  45. </template>
  46. </tabbar-item>
  47. <tabbar-item replace to="/plan">
  48. <span>农事方案</span>
  49. <template #icon="props">
  50. <img
  51. :src="
  52. props.active
  53. ? require('@/assets/img/tab_bar/farm-active.png')
  54. : require('@/assets/img/tab_bar/farm.png')
  55. "
  56. />
  57. </template>
  58. </tabbar-item>
  59. <tabbar-item replace to="/message">
  60. <span>农服农资</span>
  61. <template #icon="props">
  62. <img
  63. :src="
  64. props.active
  65. ? require('@/assets/img/tab_bar/service-active.png')
  66. : require('@/assets/img/tab_bar/service.png')
  67. "
  68. />
  69. </template>
  70. </tabbar-item>
  71. <tabbar-item replace to="/mine">
  72. <span>个人中心</span>
  73. <template #icon="props">
  74. <img
  75. :src="
  76. props.active
  77. ? require('@/assets/img/tab_bar/mine-active.png')
  78. : require('@/assets/img/tab_bar/mine.png')
  79. "
  80. />
  81. </template>
  82. </tabbar-item>
  83. </Tabbar>
  84. <!-- 开启底部安全区适配 -->
  85. <number-keyboard safe-area-inset-bottom />
  86. </template>
  87. <script setup>
  88. import { NumberKeyboard } from "vant";
  89. import { Tabbar, TabbarItem } from "vant";
  90. import { nextTick, watch, onMounted, ref } from "vue";
  91. import { useRoute, useRouter } from "vue-router";
  92. import { useStore } from "vuex";
  93. // import {NH,NF,NZ,EXPERT} from "@/common/user_role";
  94. const store = useStore();
  95. const route = useRoute();
  96. const router = useRouter();
  97. // 首页loading加载完才显示底部导航栏
  98. const showTab = ref(false);
  99. // 0: 农户, 1: 专家, 2:农资农服
  100. const curRole = ref(1);
  101. let tabBarHeight = 0;
  102. onMounted(() => {
  103. setTimeout(() => {
  104. if (route.meta.showTabbar) {
  105. showTab.value = true;
  106. }
  107. nextTick(() => {
  108. const tabBarElement = document.querySelector(".van-tabbar");
  109. if (tabBarElement) {
  110. tabBarHeight = tabBarElement.offsetHeight;
  111. localStorage.setItem("tabBarHeight", tabBarHeight);
  112. store.commit("home/SET_TAB_BAR_HEIGHT", tabBarHeight);
  113. }
  114. });
  115. }, 500);
  116. });
  117. watch(
  118. () => route.name,
  119. (newName, oldName) => {
  120. // 在这里执行你的自定义逻辑
  121. showTab.value = false;
  122. if (route.meta.showTabbar) {
  123. showTab.value = true;
  124. }
  125. nextTick(() => {
  126. const tabBarElement = document.querySelector(".van-tabbar");
  127. if (tabBarElement) {
  128. tabBarHeight = tabBarElement.offsetHeight;
  129. localStorage.setItem("tabBarHeight", tabBarHeight);
  130. store.commit("home/SET_TAB_BAR_HEIGHT", tabBarHeight);
  131. }
  132. });
  133. },
  134. { immediate: false }
  135. );
  136. </script>
  137. <style lang="scss" scoped>
  138. .tabbar {
  139. position: fixed;
  140. pointer-events: all;
  141. z-index: 9999;
  142. }
  143. </style>