s-tabbar.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="u-page__item" v-if="tabbar?.list.length > 0">
  3. <su-tabbar
  4. :value="path"
  5. :fixed="true"
  6. :placeholder="true"
  7. :safeAreaInsetBottom="true"
  8. :inactiveColor="tabbar.inactiveColor"
  9. :activeColor="tabbar.activeColor"
  10. :midTabBar="tabbar.mode === 2"
  11. :customStyle="tabbarStyle"
  12. >
  13. <su-tabbar-item
  14. v-for="(item, index) in tabbar.list"
  15. :key="item.text"
  16. :text="item.text"
  17. :name="item.url"
  18. :isCenter="getTabbarCenter(index)"
  19. :centerImage="sheep.$url.cdn(item.inactiveIcon)"
  20. @tap="sheep.$router.go(item.url)"
  21. >
  22. <template v-slot:active-icon>
  23. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.activeIcon)"></image>
  24. </template>
  25. <template v-slot:inactive-icon>
  26. <image class="u-page__item__slot-icon" :src="sheep.$url.cdn(item.inactiveIcon)"></image>
  27. </template>
  28. </su-tabbar-item>
  29. </su-tabbar>
  30. </view>
  31. </template>
  32. <script setup>
  33. import { computed, unref } from 'vue';
  34. import sheep from '@/sheep';
  35. const tabbar = computed(() => {
  36. return sheep.$store('app').template.basic?.tabbar;
  37. });
  38. const tabbarStyle = computed(() => {
  39. const backgroundStyle = tabbar.value.background;
  40. if (backgroundStyle.type == 'color') return { background: backgroundStyle.bgColor };
  41. if (backgroundStyle.type == 'image')
  42. return {
  43. background: `url(${sheep.$url.cdn(
  44. backgroundStyle.bgImage,
  45. )}) no-repeat top center / 100% auto`,
  46. };
  47. });
  48. const getTabbarCenter = (index) => {
  49. if (unref(tabbar).mode !== 2) return false;
  50. return unref(tabbar).list % 2 > 0
  51. ? Math.ceil(unref(tabbar).list.length / 2) === index + 1
  52. : false;
  53. };
  54. const props = defineProps({
  55. path: String,
  56. default: '',
  57. });
  58. </script>
  59. <style lang="scss">
  60. .u-page {
  61. padding: 0;
  62. &__item {
  63. &__title {
  64. color: var(--textSize);
  65. background-color: #fff;
  66. padding: 15px;
  67. font-size: 15px;
  68. &__slot-title {
  69. color: var(--textSize);
  70. font-size: 14px;
  71. }
  72. }
  73. &__slot-icon {
  74. width: 25px;
  75. height: 25px;
  76. }
  77. }
  78. }
  79. </style>