shopro-tabbar.vue
3.2 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
<view class="shopro-tabbar-wrap" v-if="tabbarList && tabbarList.length && showTabbar">
<view class="tabbar-box" :style="{ background: tabbarData.bgcolor || '#fff' }">
<view class="tabbar-item" v-for="(tab, index) in tabbarList" :key="tab.name" @tap="switchTabbar(tab, index)">
<view class="img-box">
<image
class="tabbar-icon"
v-if="tabbarData.style == 1 || tabbarData.style == 2"
:src="currentPath == tab.path ? tab.activeImage : tab.image"
mode="aspectFill"
></image>
<!-- 购物车角标 -->
<view v-if="tab.path == '/pages/index/cart' && cartNum" class="cu-tag badge">{{ cartNum }}</view>
</view>
<view
class="tabbar-text"
v-if="tabbarData.style == 1 || tabbarData.style == 3"
:style="{ color: currentPath == tab.path ? tabbarData.activeColor : tabbarData.color }"
>
{{ tab.name }}
</view>
</view>
</view>
</view>
</template>
<script>
import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
export default {
name: 'shoproTabbar',
components: {},
data() {
return {};
},
props: {
queryObj: {
type: Object,
default: function() {
return {id:13};
}
}
},
computed: {
...mapState({
templateData: state => state.init.templateData.tabbar,
cartNum: state => state.cart.cartNum
}),
tabbarData() {
if (this.templateData) {
return this.templateData[0].content;
}
},
tabbarList() {
if (this.tabbarData) {
return this.tabbarData.list;
}
},
currentPath() {
let pages = getCurrentPages();
let query = this.queryObj ? this.queryObj : {};
let currPage = null;
if (pages.length) {
currPage = pages[pages.length - 1].route;
}
if (Object.keys(query).length && currPage=='pages/index/view') {
let params = '';
for (let key in query) {
params += '?' + key + '=' + query[key] + '&';
}
params = params.substring(0, params.length - 1);
return '/' + currPage + params;
}
return '/' + currPage;
},
showTabbar() {
if (this.tabbarData && this.tabbarData.list) {
let arr = [];
let path = '';
arr.push('/pages/index/index');
for (let item of this.tabbarData.list) {
arr.push(item.path);
}
return arr.includes(this.currentPath);
}
}
},
created() {},
methods: {
// 切换tabbar
switchTabbar(tab, index) {
this.$tools.routerTo(tab.path, {}, true);
}
}
};
</script>
<style lang="scss">
.shopro-tabbar-wrap {
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
padding-bottom: calc(env(safe-area-inset-bottom) / 2);
position: relative;
width: 100%;
z-index: 70;
.tabbar-box {
position: fixed;
display: flex;
align-items: center;
width: 100%;
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
border-top: 1rpx solid #eeeeee;
background-color: #fff;
z-index: 998;
bottom: 0;
padding-bottom: calc(env(safe-area-inset-bottom) / 2);
.tabbar-item {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
.img-box {
position: relative;
.cu-tag {
right: -12px;
}
}
.tabbar-icon {
width: 50rpx;
height: 50rpx;
}
.tabbar-text {
font-size: 20rpx;
}
}
}
}
</style>