s-tabbar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import CouponApi from '@/sheep/api/promotion/coupon';
  26. const tabbar = computed(() => {
  27. return sheep.$store('app').template.basic?.tabbar;
  28. });
  29. const tabbarStyle = computed(() => {
  30. const backgroundStyle = tabbar.value.style;
  31. if (backgroundStyle.bgType === 'color') {
  32. return { background: backgroundStyle.bgColor };
  33. }
  34. if (backgroundStyle.bgType === 'img')
  35. return {
  36. background: `url(${sheep.$url.cdn(
  37. backgroundStyle.bgImg,
  38. )}) no-repeat top center / 100% auto`,
  39. };
  40. });
  41. const userInfo = computed(() => sheep.$store('user').userInfo);
  42. const routerGo = (item) => {
  43. if (item.url === '/pages/chat/index') {
  44. CouponApi.getKefuConversationByRelID({
  45. relID: 1
  46. }).then((res) => {
  47. sheep.$router.go('/pages/chat/index', { conversationId: res.data.id, relUserId: userInfo.value.id === res.data.relUserId ? res.data.userId : res.data.relUserId })
  48. })
  49. } else {
  50. sheep.$router.go(item.url)
  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. const props = defineProps({
  60. path: String,
  61. default: '',
  62. });
  63. </script>
  64. <style lang="scss">
  65. .imageClass {
  66. width: 100px;
  67. height: 100px;
  68. margin-bottom: 60px;
  69. // background: red;
  70. }
  71. .u-page {
  72. padding: 0;
  73. &__item {
  74. &__title {
  75. color: var(--textSize);
  76. background-color: #fff;
  77. padding: 15px;
  78. font-size: 15px;
  79. &__slot-title {
  80. color: var(--textSize);
  81. font-size: 14px;
  82. }
  83. }
  84. &__slot-icon {
  85. width: 25px;
  86. height: 25px;
  87. }
  88. }
  89. }
  90. :deep(.u-tabbar__content) {
  91. padding-top: 10px !important;
  92. margin-top: 10px !important;
  93. }
  94. </style>