1.0.2 • Published 1 month ago

@tanzhenxing/zx-circle v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

zx-circle 环形进度条

圆环形的进度条组件,支持进度渐变动画,兼容 H5、小程序和 APP。

引入

<script setup>
import ZxCircle from '@/components/zx-circle/zx-circle.vue';
</script>

代码演示

基础用法

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

<template>
  <zx-circle v-model:currentRate="currentRate" :rate="30" :speed="100" :text="text" />
</template>

<script setup>
import { ref, computed } from 'vue';

const currentRate = ref(0);
const text = computed(() => currentRate.value.toFixed(0) + '%');
</script>

宽度定制

通过 stroke-width 属性来控制进度条宽度,stroke-width 指的是 SVG 中 path 的宽度,默认值为 40。注意,此单位非 px

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

颜色定制

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

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

渐变色

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

<template>
  <zx-circle v-model:currentRate="currentRate" :rate="rate" :color="gradientColor" text="渐变色" />
</template>

<script setup>
import { ref } from 'vue';

const currentRate = ref(0);
const rate = ref(70);
const gradientColor = {
  '0%': '#3fecff',
  '100%': '#6149f6',
};
</script>

逆时针方向

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

<zx-circle v-model:currentRate="currentRate" :rate="rate" :clockwise="false" text="逆时针" />

大小定制

通过 size 属性设置圆环直径,单位为 rpx

<zx-circle v-model:currentRate="currentRate" :rate="rate" size="240" text="大小定制" />

起始位置

进度条默认从顶部开始,可以通过 start-position 属性设置起始位置,可选值为 top, right, bottom, left

<zx-circle v-model:currentRate="currentRate" :rate="rate" text="左侧" start-position="left" />
<zx-circle v-model:currentRate="currentRate" :rate="rate" text="右侧" start-position="right" />
<zx-circle v-model:currentRate="currentRate" :rate="rate" text="底部" start-position="bottom" />

API

Props

参数说明类型默认值
v-model:currentRate当前进度,推荐使用 v-modelNumber0
rate目标进度Number \| String100
size圆环直径,单位 rpxNumber \| String100
color进度条颜色,传入对象格式可以定义渐变色String \| Object#1989fa
layer-color轨道颜色String#ffffff
fill填充颜色Stringnone
speed动画速度(单位为 rate/s),0 表示无动画Number \| String0
text文字String-
stroke-width进度条宽度 (SVG stroke-width)Number \| String40
stroke-linecap进度条端点的形状,可选值为 square buttStringround
clockwise是否顺时针增加Booleantrue
start-position进度起始位置,可选值为 leftrightbottomStringtop

Events

事件名说明回调参数
update:currentRatecurrentRate 变化时触发currentRate: number

Slots

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

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式。

名称默认值描述
--zx-circle-layer-fillnone轨道填充颜色
--zx-circle-layer-color#fff轨道颜色
--zx-circle-stroke-width40px (逻辑像素,非物理)轨道和进度条宽度
--zx-circle-hover-stroke-color#1989fa进度条颜色
--zx-circle-stroke-linecapround进度条端点形状
--zx-circle-text-color#323233文字颜色
--zx-circle-text-font-weight500文字字重
--zx-circle-text-font-size14px (逻辑像素,非物理)文字大小
--zx-circle-text-line-height20px (逻辑像素,非物理)文字行高
1.0.2

1 month ago