Skip to content

Progress 进度条 1.0.19

手机扫码预览
23:37

组件名:rice-progress-circle

用于展示操作的进度,1.0.19 版本开始支持

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5
√(HBuilderx 4.80+)

基础用法

  • 通过percentage 可以设置当前的百分比
  • type 值设为 dashboard 可显示为仪表盘形进度条
html
<rice-progress-circle :percentage="50" />
<rice-progress-circle :percentage="50" type="dashboard"/>

自定义颜色

  • color 设置进度条激活的颜色
  • inactive-color 设置进度条未选中的颜色
html
<rice-progress-circle :percentage="50" color="#f56c6c" inactive-color="#fab5b5" />
<rice-progress-circle :percentage="value3" :color="formatColors" />

<script setup>
const value3=ref(50)
const formatColors = computed(() => {
  const percent = value3.value
  if (percent < 20) return '#f56c6c'
  if (percent < 40) return '#e6a23c'
  if (percent < 50) return '#5cb87a'
  if (percent < 60) return '#f56c6c'
  if (percent < 80) return '#845ec2'
  return '#c34a36'
})
</script>

自定义文本

  • text-size 设置文本的大小
  • text-color 设置文本的颜色
  • format 函数格式化文本的内容
html
<rice-progress-circle :percentage="value3" :text-color="formatColors" text-size="18px" :format="formatText" />
<script setup>
const value3=ref(50)
const formatText = (percent : number) : string => {
  if (percent < 20) return `拉低平均值`
  if (percent < 60) return `不合格`
  if (percent < 70) return `合格`
  if (percent <= 80) return `良好`
  if (percent >= 90) return '非常优秀'
  return `${percent}%`
}
</script>

自定义大小

  • size 可以设置整个圆环的尺寸,宽/高一致
  • stroke-width 可以设置进度条宽度,单位px
  • stroke-width typedashboard时,可以设置底部开口大小,默认60
html
<rice-progress-circle :percentage="50" size="80px" />
<rice-progress-circle :percentage="60" size="70px" :stroke-width="5" :custom-style="{margin:'0 12px'}" />
<rice-progress-circle :percentage="70" type="dashboard" size="70px" :stroke-width="5" :gap-angle="120" />

自定义插槽

html
<rice-progress-circle :percentage="slotValue" :show-text="false">
  <text class="slot-text">{{slotValue}}%</text>
  <text class="slot-text2">这是自定义内容的插槽</text>
</rice-progress-circle>

API

Props

属性名类型说明默认值
percentageString|Number进度百分比 0-100-
typeString类型,默认 circle 可选 dashboardcircle
sizeString|Number整个圆环的尺寸,宽/高一致100px
stroke-widthNumber进度条宽度,单位px8
durationNumber动画时长,默认350ms,单位ms350
show-textBoolean是否显示文字,默认true-
text-colorString文字颜色-
text-sizeString|Number文字大小-
formatFunction自定义文字格式-
colorString激活的进度条颜色-
inactive-colorString未激活的进度条颜色-
gap-angleNumbertype为dashboard时,底部开口大小60
custom-styleObject自定义样式-

类型定义

组件导出如下类型

ts
// 组件类型
const progressCircleRef = ref<RiceProgressCircleComponentPublicInstance | null>(null)