tabbar.uvue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <cl-list>
  5. <cl-list-item label="显示图标">
  6. <cl-switch v-model="isIcon"></cl-switch>
  7. </cl-list-item>
  8. <cl-list-item label="图标大一点">
  9. <cl-switch v-model="isIconSize"></cl-switch>
  10. </cl-list-item>
  11. <cl-list-item label="显示文字">
  12. <cl-switch v-model="isText"></cl-switch>
  13. </cl-list-item>
  14. <cl-list-item label="文字大一点">
  15. <cl-switch v-model="isTextSize"></cl-switch>
  16. </cl-list-item>
  17. <cl-list-item label="自定义">
  18. <cl-switch v-model="isCustom"></cl-switch>
  19. </cl-list-item>
  20. </cl-list>
  21. </view>
  22. <cl-tabbar
  23. v-model="value"
  24. :list="list"
  25. :selected-color="selectedColor"
  26. :color="color"
  27. :height="isCustom ? 80 : 60"
  28. :icon-size="isIconSize ? 36 : 28"
  29. :text-size="isTextSize ? 16 : 12"
  30. :show-icon="isIcon"
  31. :show-text="isText"
  32. :background-color="backgroundColor"
  33. :pt="{
  34. className: parseClass([[isCustom, 'rounded-full']]),
  35. footer: {
  36. className: parseClass([[isCustom, '!bg-transparent']])
  37. },
  38. footerContent: {
  39. className: parseClass([[isCustom, '!p-5 !pt-0']])
  40. }
  41. }"
  42. ></cl-tabbar>
  43. </cl-page>
  44. </template>
  45. <script lang="ts" setup>
  46. import { t } from "@/.cool";
  47. import { computed, ref } from "vue";
  48. import type { ClTabbarItem } from "@/uni_modules/cool-ui";
  49. import { getColor, isDark, parseClass } from "@/.cool";
  50. const isIcon = ref(true);
  51. const isIconSize = ref(false);
  52. const isText = ref(true);
  53. const isTextSize = ref(false);
  54. const isCustom = ref(false);
  55. const selectedColor = computed(() => getColor("primary-500"));
  56. const color = computed(() => getColor("surface-300"));
  57. const backgroundColor = computed(() => {
  58. return isDark.value
  59. ? isCustom.value
  60. ? getColor("surface-800")
  61. : getColor("surface-900")
  62. : "white";
  63. });
  64. const value = ref("home");
  65. const list = ref<ClTabbarItem[]>([
  66. {
  67. text: t("首页"),
  68. icon: "/static/demo/tabbar/home.png",
  69. selectedIcon: "/static/demo/tabbar/home2.png",
  70. value: "home"
  71. },
  72. {
  73. text: t("音乐"),
  74. icon: "/static/demo/tabbar/music.png",
  75. selectedIcon: "/static/demo/tabbar/music2.png",
  76. value: "category"
  77. },
  78. {
  79. text: t("睡眠"),
  80. icon: "/static/demo/tabbar/sleep.png",
  81. selectedIcon: "/static/demo/tabbar/sleep2.png",
  82. value: "cart"
  83. },
  84. {
  85. text: t("我的"),
  86. icon: "/static/demo/tabbar/my.png",
  87. selectedIcon: "/static/demo/tabbar/my2.png",
  88. value: "my"
  89. }
  90. ]);
  91. </script>