ut-tabar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="d-flex a-c j-sb bg-fff pd-10">
  3. <view v-for="item in navs" :key="item.id" @click="navigate(item)"
  4. class="c-#999 f-s-24 d-flex flex-cln j-c a-c flex1">
  5. <image :class="'w-64 h-64'" :src="activeTab === item.id ? item.activeIcon : item.icon" mode="widthFix" />
  6. <view class="text-center" :class="activeTab === item.id ? 'c-primary f-w-5' : ''">
  7. {{ item.label }}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="bg-fff" :style="{ height: `${safeAreaBottom}px` }"></view>
  12. </template>
  13. <script setup lang="ts">
  14. import { useInfoStore } from '@/store';
  15. import { computed } from 'vue';
  16. const showStorage = ref(false);
  17. const infoStore = useInfoStore();
  18. defineProps<{
  19. activeTab?: string; // 当前活跃的 tab 标识符:'base' | 'planting' | 'warehouse' | 'processing' | 'more'
  20. }>();
  21. const windowInfo = uni.getWindowInfo();
  22. const safeAreaBottom = windowInfo.safeAreaInsets.bottom;
  23. // 默认导航项
  24. const defaultNavs = [
  25. {
  26. id: 'base',
  27. label: '基地',
  28. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomBase.png',
  29. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomBaseActive.png',
  30. url: '/pages/plant/base/index',
  31. },
  32. {
  33. id: 'planting',
  34. label: '种养殖',
  35. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomPlantingBreeding.png',
  36. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomPlantingBreedingActive.png',
  37. url: '/pages/plant/port/index',
  38. },
  39. {
  40. id: 'processing',
  41. label: '加工包装',
  42. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomProcessingPackaging.png',
  43. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomProcessingPackagingActive.png',
  44. url: '/pages/plant/processing/index',
  45. },
  46. {
  47. id: 'storage',
  48. label: '仓储',
  49. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomWarehouse.png',
  50. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomWarehouseActive.png',
  51. url: '/pages/plant/storage/index',
  52. },
  53. {
  54. id: 'more',
  55. label: '更多',
  56. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomMore.png',
  57. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomMoreActive.png',
  58. url: '/pages/plant/more/index',
  59. },
  60. ];
  61. // 自定义导航项(仅显示 processing, storage, more)
  62. const customNavs = [
  63. {
  64. id: 'processing',
  65. label: '加工包装',
  66. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomProcessingPackaging.png',
  67. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomProcessingPackagingActive.png',
  68. url: '/pages/plant/processing/index',
  69. },
  70. {
  71. id: 'storage',
  72. label: '仓储',
  73. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomWarehouse.png',
  74. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomWarehouseActive.png',
  75. url: '/pages/plant/storage/index',
  76. },
  77. {
  78. id: 'more',
  79. label: '更多',
  80. icon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomMore.png',
  81. activeIcon: 'https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/plant/bottomMoreActive.png',
  82. url: '/pages/plant/more/index',
  83. },
  84. ];
  85. // 根据 navConfig 动态计算导航项
  86. const navs = computed(() => {
  87. if (infoStore.navConfig !== 'default') {
  88. return customNavs;
  89. }
  90. // 默认显示全部导航项
  91. return defaultNavs;
  92. });
  93. function navigate(item: { id: string; url: string }) {
  94. // certain tabs should clear showStorage flag
  95. if (item.id === 'base' || item.id === 'planting') {
  96. showStorage.value = false;
  97. }
  98. uni.$u.route({ type: 'switchTab', url: item.url });
  99. }
  100. </script>