s-tabbar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="u-page__item">
  3. <su-tabbar
  4. :value="path"
  5. :fixed="true"
  6. :placeholder="true"
  7. :safeAreaInsetBottom="true"
  8. :inactiveColor="state.tabbar.style.color"
  9. :activeColor="state.tabbar.style.activeColor"
  10. :midTabBar="state.tabbar.mode === 2"
  11. :customStyle="tabbarStyle"
  12. >
  13. <su-tabbar-item
  14. v-for="(item, index) in state.tabbar.items"
  15. :key="item.text"
  16. :text="item.text"
  17. :name="item.url"
  18. :badge="item.badge"
  19. :dot="item.dot"
  20. :badgeStyle="state.tabbar.badgeStyle"
  21. :isCenter="getTabbarCenter(index)"
  22. :centerImage="item.iconUrl"
  23. @tap="sheep.$router.go(item.url)"
  24. >
  25. <template v-slot:active-icon>
  26. <image class="u-page__item__slot-icon" :src="item.activeIconUrl"></image>
  27. </template>
  28. <template v-slot:inactive-icon>
  29. <image class="u-page__item__slot-icon" :src="item.iconUrl"></image>
  30. </template>
  31. </su-tabbar-item>
  32. </su-tabbar>
  33. </view>
  34. </template>
  35. <script setup>
  36. import { computed, reactive } from 'vue';
  37. import sheep from '@/common';
  38. import SuTabbar from '@/common/ui/su-tabbar/su-tabbar.vue';
  39. const state = reactive({
  40. tabbar: {
  41. mode: 2,
  42. style:{
  43. bgType: 'color',
  44. bgColor: '#ffffff',
  45. bgImg: '',
  46. activeColor:'#35E89A',
  47. color:'#222222'
  48. },
  49. badgeStyle: {},
  50. items:[
  51. {
  52. text:'首页',
  53. url:'/pages/index/index',
  54. badge:0,
  55. dot: false,
  56. iconUrl:'/static/homeIconUrl.png',
  57. activeIconUrl:'/static/homeActiveIconUrl.png'
  58. },
  59. {
  60. text:'任务创建',
  61. url:'/pages/task/create',
  62. badge:0,
  63. dot: false,
  64. iconUrl:'/static/createIconUrl.png',
  65. },
  66. {
  67. text:'我的',
  68. url:'/pages/index/user',
  69. badge:10,
  70. dot: false,
  71. iconUrl:'/static/userIconUrl.png',
  72. activeIconUrl:'/static/userActiveIconUrl.png'
  73. }
  74. ]
  75. },
  76. })
  77. const tabbarStyle = computed(() => {
  78. const backgroundStyle = state.tabbar.style;
  79. if (backgroundStyle.bgType === 'color') {
  80. return { background: backgroundStyle.bgColor };
  81. }
  82. if (backgroundStyle.bgType === 'img')
  83. return {
  84. background: `url(${backgroundStyle.bgImg}) no-repeat top center / 100% auto`,
  85. };
  86. });
  87. const getTabbarCenter = (index) => {
  88. if (state.tabbar.mode !== 2) return false;
  89. return state.tabbar.items.length % 2 > 0
  90. ? Math.ceil(state.tabbar.items.length / 2) === index + 1
  91. : false;
  92. };
  93. const props = defineProps({
  94. path: String,
  95. default: '',
  96. });
  97. </script>
  98. <style lang="scss">
  99. .u-page {
  100. padding: 0;
  101. &__item {
  102. &__title {
  103. color: var(--textSize);
  104. background-color: #fff;
  105. padding: 15px;
  106. font-size: 15px;
  107. &__slot-title {
  108. color: var(--textSize);
  109. font-size: 14px;
  110. }
  111. }
  112. &__slot-icon {
  113. width: 25px;
  114. height: 25px;
  115. }
  116. }
  117. }
  118. </style>