s-tabbar.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 v-if="item.text" class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.iconUrl)"></image>
  15. <image v-else class="imageClass" :src="sheep.$url.cdn(item.iconUrl)"></image>
  16. </template>
  17. </su-tabbar-item>
  18. </su-tabbar>
  19. </view>
  20. </template>
  21. <script setup>
  22. import { computed, unref } from 'vue';
  23. import sheep from '@/sheep';
  24. import SuTabbar from '@/sheep/ui/su-tabbar/su-tabbar.vue';
  25. const tabbar = computed(() => {
  26. return sheep.$store('app').template.basic?.tabbar;
  27. });
  28. const tabbarStyle = computed(() => {
  29. const backgroundStyle = tabbar.value.style;
  30. if (backgroundStyle.bgType === 'color') {
  31. return { background: backgroundStyle.bgColor };
  32. }
  33. if (backgroundStyle.bgType === 'img')
  34. return {
  35. background: `url(${sheep.$url.cdn(
  36. backgroundStyle.bgImg,
  37. )}) no-repeat top center / 100% auto`,
  38. };
  39. });
  40. const getTabbarCenter = (index) => {
  41. if (unref(tabbar).mode !== 2) return false;
  42. return unref(tabbar).items % 2 > 0
  43. ? Math.ceil(unref(tabbar).items.length / 2) === index + 1
  44. : false;
  45. };
  46. const props = defineProps({
  47. path: String,
  48. default: '',
  49. });
  50. </script>
  51. <style lang="scss">
  52. .imageClass {
  53. width: 100px;
  54. height: 100px;
  55. margin-bottom: 60px;
  56. // background: red;
  57. }
  58. .u-page {
  59. padding: 0;
  60. &__item {
  61. &__title {
  62. color: var(--textSize);
  63. background-color: #fff;
  64. padding: 15px;
  65. font-size: 15px;
  66. &__slot-title {
  67. color: var(--textSize);
  68. font-size: 14px;
  69. }
  70. }
  71. &__slot-icon {
  72. width: 25px;
  73. height: 25px;
  74. }
  75. }
  76. }
  77. :deep(.u-tabbar__content) {
  78. padding-top: 10px !important;
  79. margin-top: 10px !important;
  80. }
  81. </style>