NavbarRightButton.vue
1.68 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
<template>
<view class="navbar-right-button" @click="onClick">
<uv-icon :name="iconName" :color="iconColor" :size="iconSize"></uv-icon>
<text v-if="showText" class="button-text" :style="{ color: textColor }">{{ text }}</text>
<view v-if="showBadge" class="badge">{{ badgeText }}</view>
</view>
</template>
<script setup>
import { computed } from 'vue';
// 定义props
const props = defineProps({
// 图标名称
iconName: {
type: String,
default: 'more-dot-fill'
},
// 图标颜色
iconColor: {
type: String,
default: '#FFFFFF'
},
// 图标大小
iconSize: {
type: [String, Number],
default: '48rpx'
},
// 按钮文本
text: {
type: String,
default: ''
},
// 文本颜色
textColor: {
type: String,
default: '#FFFFFF'
},
// 是否显示徽标
showBadge: {
type: Boolean,
default: false
},
// 徽标文本
badgeText: {
type: [String, Number],
default: ''
}
});
const showText = computed(() => props.text !== '');
const emit = defineEmits(['click']);
const onClick = () => {
emit('click');
};
</script>
<style lang="scss" scoped>
.navbar-right-button {
display: flex;
align-items: center;
justify-content: center;
position: relative;
padding: 0 20rpx;
height: 88rpx;
.button-text {
font-size: 28rpx;
margin-left: 8rpx;
}
.badge {
position: absolute;
top: 0;
right: 0;
min-width: 32rpx;
height: 32rpx;
border-radius: 16rpx;
background-color: #FF4D4F;
color: #FFFFFF;
font-size: 20rpx;
display: flex;
align-items: center;
justify-content: center;
padding: 0 8rpx;
transform: translate(50%, -30%);
}
}
</style>