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="router.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. [
  27. router.path() == item.pagePath,
  28. '!text-primary-500',
  29. '!text-surface-400'
  30. ]
  31. ])
  32. }"
  33. >{{ t(item.text!) }}</cl-text
  34. >
  35. </view>
  36. </view>
  37. </cl-footer>
  38. </template>
  39. <script setup lang="ts">
  40. import { ctx, isDark, parseClass, router } from "@/cool";
  41. import { t } from "@/locale";
  42. import { computed } from "vue";
  43. type Item = {
  44. icon: string;
  45. icon2: string;
  46. pagePath: string;
  47. text: string | null;
  48. };
  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. uni.hideTabBar();
  62. </script>
  63. <style lang="scss" scoped>
  64. .tabbar {
  65. @apply flex flex-row items-center flex-1;
  66. .tabbar-item {
  67. @apply flex flex-col items-center justify-center flex-1;
  68. }
  69. }
  70. </style>