App.vue 5.7 KB

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