s-tabbar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. :isCenter="getTabbarCenter(index)" :centerImage="sheep.$url.cdn(item.iconUrl)"
  8. @tap="sheep.$router.go(item.url)">
  9. <template v-slot:active-icon>
  10. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.activeIconUrl)"></image>
  11. </template>
  12. <template v-slot:inactive-icon>
  13. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.iconUrl)"></image>
  14. </template>
  15. </su-tabbar-item>
  16. </su-tabbar>
  17. </view>
  18. </template>
  19. <script setup>
  20. import {
  21. computed,
  22. unref
  23. } from 'vue';
  24. import sheep from '@/sheep';
  25. const props = defineProps({
  26. path: {
  27. type: String,
  28. default: '',
  29. },
  30. tabbar: {
  31. type: Object,
  32. default: () => {}
  33. }
  34. });
  35. const tabbar = computed(() => {
  36. if (props.tabbar) return props.tabbar;
  37. console.log(sheep.$store('app').template.home.tabBar)
  38. return sheep.$store('app').template.home.tabBar
  39. });
  40. const tabbarStyle = computed(() => {
  41. const backgroundStyle = tabbar.value.style;
  42. if (backgroundStyle.bgType === 'color') {
  43. return {
  44. background: backgroundStyle.bgColor
  45. };
  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. </script>
  61. <style lang="scss">
  62. .u-page {
  63. padding: 0;
  64. &__item {
  65. &__title {
  66. color: var(--textSize);
  67. background-color: #fff;
  68. padding: 15px;
  69. font-size: 15px;
  70. &__slot-title {
  71. color: var(--textSize);
  72. font-size: 14px;
  73. }
  74. }
  75. &__slot-icon {
  76. width: 25px;
  77. height: 25px;
  78. }
  79. }
  80. }
  81. </style>