App.vue 6.2 KB

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