tabbar.uvue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <cl-footer
  3. :pt="{
  4. content: {
  5. className: '!p-0 h-[60px]'
  6. }
  7. }"
  8. >
  9. <view class="tabbar" :class="{ 'is-dark': isDark }">
  10. <view
  11. class="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. type Item = {
  40. icon: string;
  41. icon2: string;
  42. pagePath: string;
  43. text: string | null;
  44. };
  45. const path = computed(() => router.path());
  46. // tabbar 列表
  47. const list = computed<Item[]>(() => {
  48. return (ctx.tabBar.list ?? []).map((e) => {
  49. return {
  50. icon: e.iconPath!,
  51. icon2: e.selectedIconPath!,
  52. pagePath: e.pagePath,
  53. text: t(e.text?.replaceAll("%", "")!)
  54. } as Item;
  55. });
  56. });
  57. // 隐藏原生 tabBar
  58. // #ifndef MP
  59. uni.hideTabBar();
  60. // #endif
  61. </script>
  62. <style lang="scss" scoped>
  63. .tabbar {
  64. @apply flex flex-row items-center flex-1;
  65. .tabbar-item {
  66. @apply flex flex-col items-center justify-center flex-1;
  67. }
  68. }
  69. </style>