s-tabbar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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)" @tap="routerGo(item)">
  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 v-if="item.text" class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.iconUrl)"></image>
  14. <image v-else class="imageClass" :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. import CouponApi from '@/sheep/api/promotion/coupon';
  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 userInfo = computed(() => sheep.$store('user').userInfo);
  41. const routerGo = (item) => {
  42. if (item.url === '/pages/chat/index') {
  43. CouponApi.getKefuConversationByRelID({
  44. relID: 1
  45. }).then((res) => {
  46. sheep.$router.go('/pages/chat/index', { conversationId: res.data.id, relUserId: userInfo.value.id === res.data.relUserId ? res.data.userId : res.data.relUserId })
  47. })
  48. } else {
  49. sheep.$router.go(item.url)
  50. }
  51. }
  52. const getTabbarCenter = (index) => {
  53. if (unref(tabbar).mode !== 2) return false;
  54. return unref(tabbar).items % 2 > 0
  55. ? Math.ceil(unref(tabbar).items.length / 2) === index + 1
  56. : false;
  57. };
  58. const props = defineProps({
  59. path: String,
  60. default: '',
  61. });
  62. </script>
  63. <style lang="scss">
  64. .imageClass {
  65. width: 100px;
  66. height: 100px;
  67. margin-bottom: 60px;
  68. // background: red;
  69. }
  70. .u-page {
  71. padding: 0;
  72. &__item {
  73. &__title {
  74. color: var(--textSize);
  75. background-color: #fff;
  76. padding: 15px;
  77. font-size: 15px;
  78. &__slot-title {
  79. color: var(--textSize);
  80. font-size: 14px;
  81. }
  82. }
  83. &__slot-icon {
  84. width: 25px;
  85. height: 25px;
  86. }
  87. }
  88. }
  89. :deep(.u-tabbar__content) {
  90. padding-top: 10px !important;
  91. margin-top: 10px !important;
  92. }
  93. </style>