tab-bar.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script setup lang="ts">
  2. import config from "@/core/config"
  3. import type { TabBar } from "@/core/types"
  4. import appStore from "@/stores"
  5. const barList = computed(() => {
  6. const list = appStore.tabBarStore.getList()
  7. // console.log("LIST_BAR", list)
  8. return list
  9. })
  10. function changeActive(item: any) {
  11. appStore.tabBarStore.switchTab(item)
  12. }
  13. const currentTab = computed(() => {
  14. const name = appStore.tabBarStore.getCurrent()
  15. // console.log("NAME_BAR", name)
  16. return name
  17. })
  18. const getIconClass = (item: TabBar) => {
  19. let str = ""
  20. str += currentTab.value == item.name ? item.selectedIcon : item.icon
  21. return str
  22. }
  23. </script>
  24. <template>
  25. <view
  26. v-if="config.dyTabBar"
  27. class="d-fcv w-100 bg-white border-top border-t-1 border-gray-4"
  28. style="position: fixed; bottom: 0; left: 0; right: 0"
  29. >
  30. <view
  31. class="d-fc flex-column w-100 pt-8 pb-10"
  32. :class="{ 'border-left border-l-1 border-gray-4': index > 0, 'border-r-1': index > 0 }"
  33. v-for="(item, index) in barList"
  34. :key="index"
  35. @click="changeActive(item)"
  36. >
  37. <i v-if="item.icon" class="fs-30" :class="getIconClass(item)"></i>
  38. <image
  39. v-else-if="item.iconPath"
  40. class="w-30px h-30px"
  41. :src="currentTab === item.name ? item.selectedIconPath : item.iconPath"
  42. ></image>
  43. <view class="fs-12 mt-2" :class="{ 'text-vb fs-13': currentTab === item.name }">{{ item.text }}</view>
  44. </view>
  45. </view>
  46. </template>