index.vue 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <script setup lang="ts">
  2. import indexHome from './components/index.vue'
  3. import cart from './components/cart.vue'
  4. import classfiy from './components/classfiy.vue'
  5. import my from './components/my.vue'
  6. import icon2 from '@/static/tab/index1.png'
  7. import icon1 from '@/static/tab/index2.png'
  8. import icon3 from '@/static/tab/cart1.png'
  9. import icon4 from '@/static/tab/cart2.png'
  10. import class1 from '@/static/tab/class-tab0.png'
  11. import class2 from '@/static/tab/class-tab1.png'
  12. import icon5 from '@/static/tab/my1.png'
  13. import icon6 from '@/static/tab/my2.png'
  14. definePage({
  15. name: 'xsb-homeTabbar',
  16. islogin: false,
  17. style: {
  18. navigationStyle: 'custom',
  19. navigationBarTitleText: '星闪豹首页',
  20. backgroundColorBottom: '#fff',
  21. disableScroll: true,
  22. },
  23. })
  24. const { ScrollDown } = storeToRefs(useSysXsbStore())
  25. const tabbarItems = ref([
  26. { name: 'xsb-home', value: null, active: true, title: '首页', icon1: '', icon2: '' },
  27. { name: 'xsb-classfiy', value: null, active: false, title: '分类', icon1: class1, icon2: class2 },
  28. { name: 'xsb-cart', value: null, active: false, title: '购物车', icon1: icon3, icon2: icon4 },
  29. { name: 'xsb-my', value: null, active: false, title: '我的', icon1: icon5, icon2: icon6 },
  30. ])
  31. const tabbarName = ref('xsb-home')
  32. function handleTabbarChange({ value }: { value: string }) {
  33. setTabbarItemActive(value)
  34. tabbarName.value = value
  35. }
  36. function setTabbarItemActive(name: string) {
  37. tabbarItems.value.forEach((item) => {
  38. if (item.name === name) {
  39. item.active = true
  40. }
  41. else {
  42. item.active = false
  43. }
  44. })
  45. }
  46. function handleClick() {
  47. uni.pageScrollTo({
  48. duration: 50,
  49. scrollTop: 0,
  50. })
  51. }
  52. onLoad(() => {
  53. ScrollDown.value = false
  54. })
  55. </script>
  56. <template>
  57. <view class="page-xsb">
  58. <indexHome v-if="tabbarName == 'xsb-home'" />
  59. <cart v-if="tabbarName == 'xsb-cart'" />
  60. <classfiy v-if="tabbarName == 'xsb-classfiy'" />
  61. <my v-if="tabbarName == 'xsb-my'" />
  62. <wd-tabbar
  63. :model-value="tabbarName" safe-area-inset-bottom placeholder fixed :bordered="false"
  64. custom-class="custom-tab" :custom-style="`box-shadow:${tabbarName == 'xsb-cart' ? '' : ' 0rpx -6rpx 12rpx 2rpx rgba(0, 0, 0, 0.09)'}`"
  65. @change="handleTabbarChange"
  66. >
  67. <wd-tabbar-item
  68. v-for="(item, index) in tabbarItems" :key="index" :name="item.name"
  69. :value="useSysXsbStore().getTabbarItemValue(item.name)" :title="index == 0 && item.active ? '' : item.title"
  70. @change="handleTabbarChange"
  71. >
  72. <template #icon="{ active }">
  73. <template v-if="index == 0 && !active">
  74. <image src="@/static/tab/index.png" class="h44rpx w44rpx" />
  75. </template>
  76. <template v-else-if="index == 0 && active">
  77. <image v-if="ScrollDown" :src="icon1" class="h74rpx w74rpx" @click="handleClick" />
  78. <image v-else :src="icon2" class="h74rpx w74rpx" />
  79. </template>
  80. <template v-else-if="index != 0">
  81. <image v-if="active" :src="item.icon2" class="h44rpx w44rpx" />
  82. <image v-else :src="item.icon1" class="h44rpx w44rpx" />
  83. </template>
  84. </template>
  85. </wd-tabbar-item>
  86. </wd-tabbar>
  87. </view>
  88. </template>
  89. <style scoped>
  90. </style>