|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <view class="content">
|
|
|
3
|
+ <view class="nav">
|
|
|
4
|
+ <!-- 选项卡水平方向滑动,scroll-with-animation是滑动到下一个选项时,有一个延时效果 -->
|
|
|
5
|
+ <scroll-view
|
|
|
6
|
+ class="tab-scroll"
|
|
|
7
|
+ scroll-x="true"
|
|
|
8
|
+ scroll-with-animation
|
|
|
9
|
+ :scroll-left="scrollLeft"
|
|
|
10
|
+ >
|
|
|
11
|
+ <view class="tab-scroll_box">
|
|
|
12
|
+ <!-- 选项卡类别列表 -->
|
|
|
13
|
+ <view
|
|
|
14
|
+ class="tab-scroll_item"
|
|
|
15
|
+ v-for="(item, index) in category"
|
|
|
16
|
+ :key="index"
|
|
|
17
|
+ :class="{ active: isActive == index }"
|
|
|
18
|
+ @click="chenked(index, item)"
|
|
|
19
|
+ >
|
|
|
20
|
+ <view class="tile-box">
|
|
|
21
|
+ <text class="name-box">{{ item.name }}</text>
|
|
|
22
|
+ <text class="count">
|
|
|
23
|
+ {{ item.count || 0 }}
|
|
|
24
|
+ </text>
|
|
|
25
|
+ </view>
|
|
|
26
|
+ </view>
|
|
|
27
|
+ </view>
|
|
|
28
|
+ </scroll-view>
|
|
|
29
|
+ </view>
|
|
|
30
|
+ <!-- <swiper @change="change" :current="isActive" class="swiper-content" :style="fullHeight">
|
|
|
31
|
+ <swiper-item class="swiperitem-content">
|
|
|
32
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
33
|
+ <view class="nav_item" >
|
|
|
34
|
+ 1
|
|
|
35
|
+ </view>
|
|
|
36
|
+ </scroll-view>
|
|
|
37
|
+ </swiper-item>
|
|
|
38
|
+ <swiper-item class="swiperitem-content">
|
|
|
39
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
40
|
+ <view class="nav_item" >
|
|
|
41
|
+ 2
|
|
|
42
|
+ </view>
|
|
|
43
|
+ </scroll-view>
|
|
|
44
|
+ </swiper-item>
|
|
|
45
|
+ <swiper-item class="swiperitem-content">
|
|
|
46
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
47
|
+ <view class="nav_item" >
|
|
|
48
|
+ 3
|
|
|
49
|
+ </view>
|
|
|
50
|
+ </scroll-view>
|
|
|
51
|
+ </swiper-item>
|
|
|
52
|
+ <swiper-item class="swiperitem-content">
|
|
|
53
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
54
|
+ <view class="nav_item" >
|
|
|
55
|
+ 4
|
|
|
56
|
+ </view>
|
|
|
57
|
+ </scroll-view>
|
|
|
58
|
+ </swiper-item>
|
|
|
59
|
+ <swiper-item class="swiperitem-content">
|
|
|
60
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
61
|
+ <view class="nav_item" >
|
|
|
62
|
+ 5
|
|
|
63
|
+ </view>
|
|
|
64
|
+ </scroll-view>
|
|
|
65
|
+ </swiper-item>
|
|
|
66
|
+ <swiper-item class="swiperitem-content">
|
|
|
67
|
+ <scroll-view scroll-y style="height: 100%;">
|
|
|
68
|
+ <view class="nav_item" >
|
|
|
69
|
+ 6
|
|
|
70
|
+ </view>
|
|
|
71
|
+ </scroll-view>
|
|
|
72
|
+ </swiper-item>
|
|
|
73
|
+ </swiper> -->
|
|
|
74
|
+ </view>
|
|
|
75
|
+</template>
|
|
|
76
|
+<script>
|
|
|
77
|
+export default {
|
|
|
78
|
+ props: {
|
|
|
79
|
+ category: {
|
|
|
80
|
+ type: Array,
|
|
|
81
|
+ default: () => []
|
|
|
82
|
+ },
|
|
|
83
|
+ isShowNumber: {
|
|
|
84
|
+ type: Boolean,
|
|
|
85
|
+ default: true
|
|
|
86
|
+ },
|
|
|
87
|
+ curruntActive: {
|
|
|
88
|
+ type: [Number, String],
|
|
|
89
|
+ default: 0
|
|
|
90
|
+ }
|
|
|
91
|
+ },
|
|
|
92
|
+ watch: {
|
|
|
93
|
+ // swiper与上面选项卡联动
|
|
|
94
|
+ currentindex(newval) {
|
|
|
95
|
+ this.isActive = newval;
|
|
|
96
|
+ this.scrollLeft = 0;
|
|
|
97
|
+ // 滑动swiper后,每个选项距离其父元素最左侧的距离
|
|
|
98
|
+ for (let i = 0; i < newval - 1; i++) {
|
|
|
99
|
+ this.scrollLeft += this.category[i].width;
|
|
|
100
|
+ }
|
|
|
101
|
+ }
|
|
|
102
|
+ },
|
|
|
103
|
+ data() {
|
|
|
104
|
+ return {
|
|
|
105
|
+ isActive: 0,
|
|
|
106
|
+ index: 0,
|
|
|
107
|
+ currentindex: 0,
|
|
|
108
|
+
|
|
|
109
|
+ contentScrollW: 0, // 导航区宽度
|
|
|
110
|
+ scrollLeft: 0, // 横向滚动条位置
|
|
|
111
|
+ fullHeight: ""
|
|
|
112
|
+ };
|
|
|
113
|
+ },
|
|
|
114
|
+ mounted() {
|
|
|
115
|
+ var that = this;
|
|
|
116
|
+ this.isActive = this.curruntActive;
|
|
|
117
|
+ //获取手机屏幕的高度,让其等于swiper的高度,从而使屏幕充满
|
|
|
118
|
+ uni.getSystemInfo({
|
|
|
119
|
+ success: function (res) {
|
|
|
120
|
+ that.fullHeight = "height:" + res.windowHeight + "px";
|
|
|
121
|
+ }
|
|
|
122
|
+ });
|
|
|
123
|
+ // 获取标题区域宽度,和每个子元素节点的宽度
|
|
|
124
|
+ this.getScrollW();
|
|
|
125
|
+ },
|
|
|
126
|
+ methods: {
|
|
|
127
|
+ // 获取标题区域宽度,和每个子元素节点的宽度以及元素距离左边栏的距离
|
|
|
128
|
+ getScrollW() {
|
|
|
129
|
+ const query = uni.createSelectorQuery().in(this);
|
|
|
130
|
+ query
|
|
|
131
|
+ .select(".tab-scroll")
|
|
|
132
|
+ .boundingClientRect((data) => {
|
|
|
133
|
+ this.contentScrollW = data.width;
|
|
|
134
|
+ })
|
|
|
135
|
+ .exec();
|
|
|
136
|
+ query
|
|
|
137
|
+ .selectAll(".tab-scroll_item")
|
|
|
138
|
+ .boundingClientRect((data) => {
|
|
|
139
|
+ let dataLen = data.length;
|
|
|
140
|
+ for (let i = 0; i < dataLen; i++) {
|
|
|
141
|
+ this.category[i].left = data[i].left;
|
|
|
142
|
+ this.category[i].width = data[i].width;
|
|
|
143
|
+ }
|
|
|
144
|
+ })
|
|
|
145
|
+ .exec();
|
|
|
146
|
+ },
|
|
|
147
|
+ // 当前点击子元素靠左留一个选项展示,子元素宽度不相同也可实现
|
|
|
148
|
+ chenked(index, item) {
|
|
|
149
|
+ this.isActive = index;
|
|
|
150
|
+ this.scrollLeft = 0;
|
|
|
151
|
+ for (let i = 0; i < index - 1; i++) {
|
|
|
152
|
+ this.scrollLeft += this.category[i].width;
|
|
|
153
|
+ }
|
|
|
154
|
+ this.$emit("tabs", { index, item });
|
|
|
155
|
+ },
|
|
|
156
|
+ // swiper滑动时,获取其索引,也就是第几个
|
|
|
157
|
+ change(e) {
|
|
|
158
|
+ const { current } = e.detail;
|
|
|
159
|
+ this.currentindex = current;
|
|
|
160
|
+ }
|
|
|
161
|
+ }
|
|
|
162
|
+};
|
|
|
163
|
+</script>
|
|
|
164
|
+<style lang="scss">
|
|
|
165
|
+.content {
|
|
|
166
|
+ display: flex;
|
|
|
167
|
+ flex-direction: column;
|
|
|
168
|
+ width: 100%;
|
|
|
169
|
+ flex: 1;
|
|
|
170
|
+ .nav {
|
|
|
171
|
+ background-color: #fff;
|
|
|
172
|
+ // position: fixed;
|
|
|
173
|
+ z-index: 99;
|
|
|
174
|
+ width: 100%;
|
|
|
175
|
+ align-items: center;
|
|
|
176
|
+ // min-height: 40rpx;
|
|
|
177
|
+ .tab-scroll {
|
|
|
178
|
+ flex: 1;
|
|
|
179
|
+ overflow: hidden;
|
|
|
180
|
+ box-sizing: border-box;
|
|
|
181
|
+ padding-left: 30rpx;
|
|
|
182
|
+ padding-right: 30rpx;
|
|
|
183
|
+ .tab-scroll_box {
|
|
|
184
|
+ display: flex;
|
|
|
185
|
+ align-items: center;
|
|
|
186
|
+ flex-wrap: nowrap;
|
|
|
187
|
+ box-sizing: border-box;
|
|
|
188
|
+ height: 100rpx;
|
|
|
189
|
+ .tab-scroll_item {
|
|
|
190
|
+ line-height: 80rpx;
|
|
|
191
|
+ margin-right: 35rpx;
|
|
|
192
|
+ flex-shrink: 0;
|
|
|
193
|
+ display: flex;
|
|
|
194
|
+ justify-content: center;
|
|
|
195
|
+ font-size: 30rpx;
|
|
|
196
|
+ padding-top: 10rpx;
|
|
|
197
|
+ color: #333;
|
|
|
198
|
+ .tile-box {
|
|
|
199
|
+ display: flex;
|
|
|
200
|
+ align-items: center;
|
|
|
201
|
+ flex-direction: column;
|
|
|
202
|
+ .count {
|
|
|
203
|
+ height: initial;
|
|
|
204
|
+ }
|
|
|
205
|
+ }
|
|
|
206
|
+ }
|
|
|
207
|
+ }
|
|
|
208
|
+ }
|
|
|
209
|
+ }
|
|
|
210
|
+ .swiper-content {
|
|
|
211
|
+ padding-top: 120rpx;
|
|
|
212
|
+ // flex: 1;
|
|
|
213
|
+ .swiperitem-content {
|
|
|
214
|
+ background-color: #ffffff;
|
|
|
215
|
+ .nav_item {
|
|
|
216
|
+ background-color: #ffffff;
|
|
|
217
|
+ padding: 20rpx 40rpx 0rpx 40rpx;
|
|
|
218
|
+ }
|
|
|
219
|
+ }
|
|
|
220
|
+ }
|
|
|
221
|
+}
|
|
|
222
|
+.active {
|
|
|
223
|
+ position: relative;
|
|
|
224
|
+ color: #1f7cff !important;
|
|
|
225
|
+ font-weight: 600;
|
|
|
226
|
+}
|
|
|
227
|
+.active::after {
|
|
|
228
|
+ content: "";
|
|
|
229
|
+ position: absolute;
|
|
|
230
|
+ width: 50rpx;
|
|
|
231
|
+ height: 8rpx;
|
|
|
232
|
+ background-color: #1f7cff;
|
|
|
233
|
+ left: 0px;
|
|
|
234
|
+ right: 0px;
|
|
|
235
|
+ bottom: 0px;
|
|
|
236
|
+ margin: auto;
|
|
|
237
|
+ border-radius: 8rpx;
|
|
|
238
|
+ margin-top: 10rpx;
|
|
|
239
|
+ transition: all 0.3s;
|
|
|
240
|
+}
|
|
|
241
|
+/* 隐藏滚动条,但依旧具备可以滚动的功能 */
|
|
|
242
|
+/deep/.uni-scroll-view::-webkit-scrollbar {
|
|
|
243
|
+ display: none;
|
|
|
244
|
+}
|
|
|
245
|
+</style>
|