tabbar.vue 2.2 KB

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