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
113
114
115
116
117
118
119
120
121
122
123
124
| <!-- 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)"
| >
| <image
| :src="selected === item.key ? item.selectedIconPath : item.iconPath"
| :class="{'tabbar-icon': true, 'video-add': item.key == 'video'}"
| />
| <text class="tabbar-text" v-if="item.text" :style="{color: selected === item.key ? selectedTextColor : color}">
| {{item.text}}
| </text>
| </view>
| </view>
| </template>
|
| <script>
| export default {
| name: "CustomTabbar",
| props: {
| selected: {
| type: String,
| default: 'index'
| },
| 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": "首页",
| "key": 'index'
| },
| {
| "pagePath": "/pages/tabbar/category/category",
| "iconPath": "/static/tabbar/category.png",
| "selectedIconPath": "/static/tabbar/category-s.png",
| "text": "商城",
| "key": 'shop'
| },
| {
| "pagePath": "/pages/tabbar/video/video",
| "iconPath": "/static/tabbar/video1.png",
| "selectedIconPath": "/static/tabbar/video1-selected.png",
| "key": 'video'
| },
| {
| "pagePath": "/pages/tabbar/cart/cartList",
| "iconPath": "/static/tabbar/cart.png",
| "selectedIconPath": "/static/tabbar/cart-s.png",
| "text": "购物车",
| "key": 'buyCar'
| },
| {
| "pagePath": "/pages/tabbar/user/my",
| "iconPath": "/static/tabbar/mine.png",
| "selectedIconPath": "/static/tabbar/mine-s.png",
| "text": "我的",
| "key": 'my'
| }
| ]
| }
| },
| methods: {
| switchTab(item) {
| console.log("执行力", item);
| if (this.selected === item.key) 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;
| }
| .video-add {
| width: 30px !important;
| height: 30px !important;
| }
| .tabbar-icon {
| width: 24px;
| height: 24px;
| margin-bottom: 4px;
| }
|
| .tabbar-text {
| font-size: 10px;
| }
| </style>
|
|