NavbarRightButton.vue 1.68 KB
<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>