s-tabbar.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="u-page__item" v-if="tabbar?.items?.length > 0">
  3. <su-tabbar
  4. :value="path"
  5. :fixed="true"
  6. :placeholder="true"
  7. :safeAreaInsetBottom="true"
  8. :inactiveColor="tabbar.style.color"
  9. :activeColor="tabbar.style.activeColor"
  10. :midTabBar="tabbar.mode === 2"
  11. :customStyle="tabbarStyle"
  12. >
  13. <su-tabbar-item
  14. v-for="(item, index) in tabbar.items"
  15. :key="item.text"
  16. :text="item.text"
  17. :name="item.url"
  18. :badge="item.badge"
  19. :dot="item.dot"
  20. :badgeStyle="tabbar.badgeStyle"
  21. :isCenter="getTabbarCenter(index)"
  22. :centerImage="sheep.$url.cdn(item.iconUrl)"
  23. @tap="sheep.$router.go(item.url)"
  24. >
  25. <template v-slot:active-icon>
  26. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.activeIconUrl)"></image>
  27. </template>
  28. <template v-slot:inactive-icon>
  29. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.iconUrl)"></image>
  30. </template>
  31. </su-tabbar-item>
  32. </su-tabbar>
  33. </view>
  34. </template>
  35. <script setup>
  36. import { computed, unref } from 'vue';
  37. import sheep from '@/sheep';
  38. import SuTabbar from '@/sheep/ui/su-tabbar/su-tabbar.vue';
  39. const tabbar = computed(() => {
  40. return sheep.$store('app').template.basic?.tabbar;
  41. });
  42. const tabbarStyle = computed(() => {
  43. const backgroundStyle = tabbar.value.style;
  44. if (backgroundStyle.bgType === 'color') {
  45. return { background: backgroundStyle.bgColor };
  46. }
  47. if (backgroundStyle.bgType === 'img')
  48. return {
  49. background: `url(${sheep.$url.cdn(
  50. backgroundStyle.bgImg,
  51. )}) no-repeat top center / 100% auto`,
  52. };
  53. });
  54. const getTabbarCenter = (index) => {
  55. if (unref(tabbar).mode !== 2) return false;
  56. return unref(tabbar).items % 2 > 0
  57. ? Math.ceil(unref(tabbar).items.length / 2) === index + 1
  58. : false;
  59. };
  60. const props = defineProps({
  61. path: String,
  62. default: '',
  63. });
  64. </script>
  65. <style lang="scss">
  66. .u-page {
  67. padding: 0;
  68. &__item {
  69. &__title {
  70. color: var(--textSize);
  71. background-color: #fff;
  72. padding: 15px;
  73. font-size: 15px;
  74. &__slot-title {
  75. color: var(--textSize);
  76. font-size: 14px;
  77. }
  78. }
  79. &__slot-icon {
  80. width: 25px;
  81. height: 25px;
  82. }
  83. }
  84. }
  85. </style>