s-tabbar.vue 2.3 KB

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