tabbar.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script lang="ts" setup>
  2. const router = useRouter()
  3. const route = useRoute()
  4. const { opcity } = storeToRefs(useSysStore())
  5. const { activeTabbar, getTabbarItemValue, setTabbarItemActive, tabbarList } = useTabbar()
  6. function handleTabbarChange({ value }: { value: string }) {
  7. setTabbarItemActive(value)
  8. router.pushTab({ name: value })
  9. }
  10. onMounted(() => {
  11. // #ifdef APP-PLUS
  12. uni.hideTabBar()
  13. // #endif
  14. nextTick(() => {
  15. if (route.name && route.name !== activeTabbar.value.name) {
  16. setTabbarItemActive(route.name)
  17. }
  18. })
  19. })
  20. function handleClick() {
  21. uni.pageScrollTo({
  22. duration: 50,
  23. scrollTop: 0,
  24. })
  25. }
  26. </script>
  27. <script lang="ts">
  28. export default {
  29. options: {
  30. addGlobalClass: true,
  31. virtualHost: true,
  32. styleIsolation: 'shared',
  33. },
  34. }
  35. </script>
  36. <template>
  37. <slot />
  38. <view class="page-tab">
  39. <wd-tabbar
  40. :model-value="activeTabbar.name" safe-area-inset-bottom placeholder fixed :bordered="false"
  41. custom-class="custom-tab" :custom-style="`box-shadow:${activeTabbar.name == 'smqjh-cart' ? '' : ' 0rpx -6rpx 12rpx 2rpx rgba(0, 0, 0, 0.09)'}`"
  42. @change="handleTabbarChange"
  43. >
  44. <wd-tabbar-item
  45. v-for="(item, index) in tabbarList" :key="index" :name="item.name"
  46. :value="getTabbarItemValue(item.name)" :title="index == 0 && item.active ? '' : item.title"
  47. >
  48. <template #icon="{ active }">
  49. <template v-if="index == 0 && !active">
  50. <i class="iconfont text-44rpx">&#xe629;</i>
  51. </template>
  52. <template v-else-if="index == 0 && active">
  53. <i v-if="opcity == 1" class="iconfont text-76rpx text-[var(--them-color)]" @click="handleClick">&#xe62b;</i>
  54. <i v-else class="iconfont text-76rpx text-[var(--them-color)]">&#xe648;</i>
  55. </template>
  56. <template v-else-if="index != 0">
  57. <text :class="[active ? 'text-[var(--them-color)]' : '']" class="iconfont text-44rpx">
  58. {{ item.icon1 }}
  59. </text>
  60. </template>
  61. </template>
  62. </wd-tabbar-item>
  63. </wd-tabbar>
  64. </view>
  65. </template>
  66. <style scoped lang="scss">
  67. .page-tab {
  68. :deep() {
  69. .custom-tab {
  70. border-radius: 28rpx 28rpx 0 0;
  71. }
  72. }
  73. }
  74. </style>