s-tabbar.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. return sheep.$store('app').template.basic?.tabbar;
  38. });
  39. const tabbarStyle = computed(() => {
  40. const backgroundStyle = tabbar.value.style;
  41. if (backgroundStyle.bgType === 'color') {
  42. return {
  43. background: backgroundStyle.bgColor
  44. };
  45. }
  46. if (backgroundStyle.bgType === 'img')
  47. return {
  48. background: `url(${sheep.$url.cdn(
  49. backgroundStyle.bgImg,
  50. )}) no-repeat top center / 100% auto`,
  51. };
  52. });
  53. const getTabbarCenter = (index) => {
  54. if (unref(tabbar).mode !== 2) return false;
  55. return unref(tabbar).items % 2 > 0 ?
  56. Math.ceil(unref(tabbar).items.length / 2) === index + 1 :
  57. false;
  58. };
  59. </script>
  60. <style lang="scss">
  61. .u-page {
  62. padding: 0;
  63. &__item {
  64. &__title {
  65. color: var(--textSize);
  66. background-color: #fff;
  67. padding: 15px;
  68. font-size: 15px;
  69. &__slot-title {
  70. color: var(--textSize);
  71. font-size: 14px;
  72. }
  73. }
  74. &__slot-icon {
  75. width: 25px;
  76. height: 25px;
  77. }
  78. }
  79. }
  80. </style>