tabbar.uvue 857 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <cl-tabbar :model-value="path" :list="list" @select="onSelect"> </cl-tabbar>
  3. </template>
  4. <script setup lang="ts">
  5. import { ctx, getConfig, isDark, router, t } from "@/.cool";
  6. import type { ClTabbarItem } from "@/uni_modules/cool-ui";
  7. import { computed } from "vue";
  8. defineOptions({
  9. name: "custom-tabbar"
  10. });
  11. // 当前路径
  12. const path = computed(() => router.path());
  13. // tabbar 列表
  14. const list = computed<ClTabbarItem[]>(() => {
  15. return (ctx.tabBar.list ?? []).map((e) => {
  16. return {
  17. icon: e.iconPath,
  18. selectedIcon: e.selectedIconPath,
  19. value: e.pagePath,
  20. text: t(e.text?.replaceAll("%", "")!)
  21. } as ClTabbarItem;
  22. });
  23. });
  24. // 选择 tabbar 项
  25. const onSelect = (item: ClTabbarItem) => {
  26. router.to(item.value);
  27. };
  28. // 隐藏原生 tabBar
  29. // #ifndef MP
  30. if (ctx.tabBar.list != null) {
  31. uni.hideTabBar();
  32. }
  33. // #endif
  34. </script>