tabbar.uvue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <cl-footer
  3. :pt="{
  4. content: {
  5. className: '!p-0 h-[60px]'
  6. }
  7. }"
  8. >
  9. <view class="custom-tabbar" :class="{ 'is-dark': isDark }">
  10. <view
  11. class="custom-tabbar-item"
  12. v-for="item in list"
  13. :key="item.pagePath"
  14. @tap="router.to(item.pagePath)"
  15. >
  16. <cl-image
  17. :src="path == item.pagePath ? item.icon2 : item.icon"
  18. :height="56"
  19. :width="56"
  20. ></cl-image>
  21. <cl-text
  22. v-if="item.text != null"
  23. :pt="{
  24. className: parseClass([
  25. '!text-xs mt-1',
  26. [path == item.pagePath, '!text-primary-500', '!text-surface-400']
  27. ])
  28. }"
  29. >{{ t(item.text!) }}</cl-text
  30. >
  31. </view>
  32. </view>
  33. </cl-footer>
  34. </template>
  35. <script setup lang="ts">
  36. import { ctx, isDark, parseClass, router } from "@/cool";
  37. import { t } from "@/locale";
  38. import { computed } from "vue";
  39. defineOptions({
  40. name: "custom-tabbar"
  41. });
  42. type Item = {
  43. icon: string;
  44. icon2: string;
  45. pagePath: string;
  46. text: string | null;
  47. };
  48. const path = computed(() => router.path());
  49. // tabbar 列表
  50. const list = computed<Item[]>(() => {
  51. return (ctx.tabBar.list ?? []).map((e) => {
  52. return {
  53. icon: e.iconPath!,
  54. icon2: e.selectedIconPath!,
  55. pagePath: e.pagePath,
  56. text: t(e.text?.replaceAll("%", "")!)
  57. } as Item;
  58. });
  59. });
  60. // 隐藏原生 tabBar
  61. // #ifndef MP
  62. uni.hideTabBar();
  63. // #endif
  64. </script>
  65. <style lang="scss" scoped>
  66. .custom-tabbar {
  67. @apply flex flex-row items-center flex-1;
  68. &-item {
  69. @apply flex flex-col items-center justify-center flex-1;
  70. }
  71. }
  72. </style>