Skip to content

Circle 环形进度条

介绍

圆环形的进度条组件,支持进度渐变动画。

引入

js
import { createApp } from 'vue';
import { Circle } from '@szhn/dh-design-mobile';

const app = createApp();
app.use(Circle);

代码演示

基础用法

rate 属性表示进度条的目标进度,v-model:current-rate 表示动画过程中的实时进度。当 rate 发生变化时,v-model:current-rate 会以 speed 的速度变化,直至达到 rate 设定的值。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="rate"
  :speed="100"
  :text="currentRate.toFixed(0) + '%'"
/>

宽度定制

通过 stroke-width 属性来控制进度条宽度。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="70"
  :stroke-width="60"
  text="宽度定制"
/>

颜色定制

通过 color 属性来控制进度条颜色,layer-color 属性来控制轨道颜色。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="70"
  layer-color="#ebedf0"
  color="#ee0a24"
  text="颜色定制"
/>

渐变色

color 属性支持传入对象格式来定义渐变色。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="70"
  :color="{ '0%': '#3fecff', '100%': '#6149f6' }"
  text="渐变色"
/>

逆时针方向

clockwise 设置为 false,进度会从逆时针方向开始。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="70"
  :clockwise="false"
  text="逆时针"
/>

大小定制

通过 size 属性设置圆环直径。

html
<van-circle
  v-model:current-rate="currentRate"
  :rate="70"
  size="120px"
  text="大小定制"
/>

起始位置

进度条默认从顶部开始,可以通过 start-position 属性设置起始位置。

html
<van-circle :current-rate="75" :rate="75" text="左侧" start-position="left" />
<van-circle :current-rate="75" :rate="75" text="右侧" start-position="right" />
<van-circle :current-rate="75" :rate="75" text="底部" start-position="bottom" />

API

Props

参数说明类型默认值
v-model:current-rate当前进度number-
rate目标进度number | string100
size圆环直径,默认单位为 pxnumber | string100px
color进度条颜色,传入对象格式可以定义渐变色string | object#1989fa
layer-color轨道颜色stringwhite
fill填充颜色stringnone
speed动画速度(单位为 rate/s)number | string0
text文字string-
stroke-width进度条宽度number | string40
stroke-linecap进度条端点的形状,可选值为 square buttstringround
clockwise是否顺时针增加booleantrue
start-position进度起始位置,可选值为 leftrightbottomCircleStartPositiontop

Slots

名称说明
default自定义文字内容

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件。

名称默认值描述
--van-circle-size100px环形进度条的尺寸
--van-circle-colorvar(--van-primary-color)进度条的颜色
--van-circle-layer-colorvar(--van-white)进度条轨道的颜色
--van-circle-text-colorvar(--van-text-color)圆形内文字的颜色
--van-circle-text-font-weightvar(--van-font-bold)圆形内文字的字重
--van-circle-text-font-sizevar(--van-font-size-md)圆形内文字的字体大小
--van-circle-text-line-heightvar(--van-line-height-md)圆形内文字的行高