绿满眶商城微信小程序-uniapp
xiangpei
2025-05-15 305691dd3759e3bd95fdd70ff46693d04f2925d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!-- components/custom-tabbar.vue -->
<template>
  <view class="custom-tabbar" :style="{backgroundColor: bgColor}">
    <view 
      v-for="(item, index) in list" 
      :key="index"
      class="tabbar-item"
      @click="switchTab(item, index)"
    >
      <image 
        :src="selected === index ? item.selectedIconPath : item.iconPath" 
        class="tabbar-icon"
      />
      <text class="tabbar-text" :style="{color: selected === index ? selectedTextColor : color}">
        {{item.text}}
      </text>
    </view>
  </view>
</template>
 
<script>
export default {
  name: "CustomTabbar",
  props: {
    selected: {
      type: Number,
      default: 0
    },
    bgColor: {
      type: String,
      default: '#333333'
    },
    selectedTextColor: {
      type: String,
      default: '#ff573e'
    }
  },
  data() {
    return {
      color: '#999999',
      list: [
            {
                "pagePath": "/pages/tabbar/index/home",
                "iconPath": "/static/tabbar/home.png",
                "selectedIconPath": "/static/tabbar/home-s.png",
                "text": "首页"
            },
            {
                "pagePath": "/pages/tabbar/category/category",
                "iconPath": "/static/tabbar/category.png",
                "selectedIconPath": "/static/tabbar/category-s.png",
                "text": "分类"
            },
        
            {
                "pagePath": "/pages/tabbar/cart/cartList",
                "iconPath": "/static/tabbar/cart.png",
                "selectedIconPath": "/static/tabbar/cart-s.png",
                "text": "购物车"
            },
            {
                "pagePath": "/pages/tabbar/user/my",
                "iconPath": "/static/tabbar/mine.png",
                "selectedIconPath": "/static/tabbar/mine-s.png",
                "text": "我的"
            }
      ]
    }
  },
  methods: {
    switchTab(item, index) {
        console.log("执行力", item, index);
      if (this.selected === index) return;
      uni.switchTab({
        url: item.pagePath
      });
    }
  }
}
</script>
 
<style>
.custom-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid #ededed;
  box-sizing: border-box;
}
 
.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
 
.tabbar-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 4px;
}
 
.tabbar-text {
  font-size: 10px;
}
</style>