tui-bottom-navigation.vue
8.33 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<template>
<view @touchmove.stop.prevent="stop">
<view class="tui-bottom-navigation" :style="{ backgroundColor: isDarkMode ? '#202020' : backgroundColor }" :class="{ 'tui-navigation-fixed': isFixed, 'tui-remove-splitLine': unlined }">
<view
class="tui-navigation-item"
:class="{ 'tui-item-after_height': splitLineScale, 'tui-last-item': index == itemList.length - 1 }"
v-for="(item, index) in itemList"
:key="index"
>
<view class="tui-item-inner" @tap="menuClick(index, item.parameter, item.type)">
<image
:src="getIcon(current,index, item)"
class="tui-navigation-img"
v-if="item.iconPath || (current == index && item.selectedIconPath && item.type == 1)"
></image>
<text
class="tui-navigation-text"
:style="{
color: isDarkMode ? '#fff' : current == index && item.type == 1 ? getSelectColor : item.color || color,
fontWeight: current == index && bold && item.type == 1 ? 'bold' : 'normal',
fontSize: fontSize
}"
>
{{ item.text }}
</text>
</view>
<view
class="tui-navigation-popup"
:class="{ 'tui-navigation-popup_show': showMenuIndex == index }"
:style="{ backgroundColor: isDarkMode ? '#4c4c4c' : subMenuBgColor, left: item.popupLeft || '50%' }"
v-if="item.itemList"
>
<view
class="tui-popup-cell"
:class="{ 'tui-first-cell': subIndex === 0, 'tui-last-cell': subIndex === item.itemList.length - 1 }"
:hover-class="subMenuHover ? (isDarkMode ? 'tui-item-dark_hover' : 'tui-item-hover') : ''"
:hover-stay-time="150"
v-for="(subItem, subIndex) in item.itemList || []"
:key="subIndex"
@tap="subMenuClick(index, item.type, subIndex, subItem.parameter || '')"
>
<text class="tui-ellipsis" :style="{ color: isDarkMode ? '#fff' : subMenuColor, fontSize: subMenufontSize, lineHeight: subMenufontSize }">
{{ subItem.text }}
</text>
</view>
<view class="tui-popup-triangle" :style="{ borderTopColor: isDarkMode ? '#4c4c4c' : subMenuBgColor }"></view>
</view>
</view>
</view>
<view class="tui-navigation-mask" :class="{ 'tui-navigation-mask_show': showMenuIndex != -1 }" @tap="handleClose"></view>
</view>
</template>
<script>
export default {
name: 'tuiBottomNavigation',
emits: ['click'],
props: {
//当前索引
current: {
type: Number,
default: 0
},
/**
* {
text: 'ThorUI',
iconPath: '/static/images/common/icon_menu_gray.png',
selectedIconPath: '/static/images/common/icon_menu_gray.png',
color: '#666',
//1-选中切换,2-跳转、请求、其他操作,3-菜单
type: 3,
//自定义参数,类型自定义
parameter: null,
//子菜单left值,不传默认50%,当菜单贴近左右两边可用此参数调整
popupLeft: '',
itemList: [
{
//不建议超过6个字,请自行控制
text: '自定义参',
//自定义参数,类型自定义
parameter: null
},
{
text: '自定义参数',
//自定义参数,类型自定义
parameter: null
}
]
}
*
* */
itemList: {
type: Array,
default: () => {
return [];
}
},
//颜色
color: {
type: String,
default: '#666'
},
//选中颜色
selectedColor: {
type: String,
default: ''
},
fontSize: {
type: String,
default: '28rpx'
},
//选中后字体是否加粗
bold: {
type: Boolean,
default: true
},
//导航条背景颜色
backgroundColor: {
type: String,
default: '#F8F8F8'
},
//item分割线高度是否缩小
splitLineScale: {
type: Boolean,
default: true
},
//二级菜单字体颜色
subMenuColor: {
type: String,
default: '#333'
},
//二级菜单字体大小
subMenufontSize: {
type: String,
default: '28rpx'
},
//二级菜单背景色 深色:#4c4c4c
subMenuBgColor: {
type: String,
default: '#fff'
},
//二级菜单是否有点击效果
subMenuHover: {
type: Boolean,
default: true
},
//是否固定在底部
isFixed: {
type: Boolean,
default: true
},
//去除导航栏顶部的线条
unlined: {
type: Boolean,
default: false
},
//是否暗黑模式 (true:所有设置颜色失效)
isDarkMode: {
type: Boolean,
default: false
}
},
data() {
return {
showMenuIndex: -1 //显示的菜单index
};
},
computed:{
getSelectColor(){
return this.selectedColor || (uni && uni.$tui && uni.$tui.color.primary) || '#5677fc';
}
},
methods: {
getIcon: function(current, index, item) {
let url = item.iconPath;
if (item.type == 1) {
url = current == index ? item.selectedIconPath || item.iconPath : item.iconPath;
}
return url;
},
stop() {
return false;
},
handleClose() {
this.showMenuIndex = -1;
},
menuClick(index, parameter, type) {
//type:1-选中切换,2-跳转、请求、其他操作,3-菜单
if (type == 3) {
this.showMenuIndex = this.showMenuIndex == index ? -1 : index;
} else {
this.showMenuIndex = -1;
this.$emit('click', {
menu: 'main', //main,sub 主菜单,子菜单
type: type,
index: index,
parameter: parameter || ''
});
}
},
subMenuClick(index, type, subIndex, parameter) {
this.showMenuIndex = -1;
this.$emit('click', {
menu: 'sub', //main,sub 主菜单,子菜单
type: type,
index: index,
subIndex: subIndex,
parameter: parameter || ''
});
}
}
};
</script>
<style scoped>
.tui-bottom-navigation {
width: 100%;
height: 100rpx;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
z-index: 999;
}
.tui-navigation-fixed {
position: fixed !important;
left: 0;
bottom: 0;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
box-sizing: content-box;
}
.tui-bottom-navigation::after {
content: '';
width: 100%;
border-top: 1px solid #bfbfbf;
position: absolute;
top: 0;
left: 0;
transform: scaleY(0.5) translateZ(0);
transform-origin: 0 0;
z-index: 1000;
}
.tui-remove-splitLine::before {
border-top: 0 !important;
}
.tui-navigation-item {
flex: 1;
height: 100rpx;
position: relative;
box-sizing: border-box;
}
.tui-item-inner {
width: 100%;
height: 100rpx;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
}
.tui-navigation-item::after {
height: 100%;
content: '';
position: absolute;
border-right: 1px solid #bfbfbf;
transform: scaleX(0.5) translateZ(0);
right: 0;
top: 0;
}
.tui-item-after_height::after {
height: 40% !important;
top: 30% !important;
}
.tui-last-item::after {
border-right: 0 !important;
}
.tui-navigation-img {
width: 32rpx;
height: 32rpx;
margin-right: 8rpx;
}
.tui-navigation-popup {
max-width: 160%;
width: auto;
position: absolute;
border-radius: 8rpx;
visibility: hidden;
opacity: 0;
transform: translate3d(-50%, 0, 0);
transform-origin: center;
transition: all 0.12s ease-in-out;
bottom: 0;
z-index: -1;
}
.tui-navigation-popup_show {
transform: translate3d(-50%, -124rpx, 0);
visibility: visible;
opacity: 1;
}
.tui-popup-triangle {
position: absolute;
width: 0;
height: 0;
border-left: 9rpx solid transparent;
border-right: 9rpx solid transparent;
border-top: 18rpx solid;
left: 50%;
bottom: -18rpx;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
z-index: 997;
}
.tui-popup-cell {
width: 100%;
padding: 32rpx 20rpx;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
flex: 1;
position: relative;
}
.tui-ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.tui-popup-cell::after {
content: '';
position: absolute;
border-bottom: 1rpx solid #eaeef1;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
bottom: 0;
right: 24rpx;
left: 24rpx;
}
.tui-item-hover {
background-color: #f1f1f1;
}
.tui-item-dark_hover {
background-color: #555;
}
.tui-first-cell {
border-top-left-radius: 8rpx;
border-top-right-radius: 8rpx;
}
.tui-last-cell {
border-bottom-left-radius: 8rpx;
border-bottom-right-radius: 8rpx;
}
.tui-last-cell::after {
border-bottom: 0 !important;
}
.tui-navigation-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 995;
transition: all 0.3s ease-in-out;
opacity: 0;
visibility: hidden;
background-color: rgba(0, 0, 0, 0);
}
.tui-navigation-mask_show {
opacity: 1;
visibility: visible;
}
</style>