# CircleProgress 进度环
环形进度指示:以 svg 双 circle(轨道 + 进度弧)表达百分比,纯受控、无内部态、
无事件。几何换算(半径 / 周长 / dasharray / 起笔旋转角)与颜色归一全部在
@lh-ui/share/core/circle-progress 纯逻辑里,本组件只做响应式胶水与模板。
modelValue 为 0-100 的受控百分比,越界由 share core 钳制(clampPercent);
startAngle 以 12 点钟方向为 0 度、顺时针为正(与时针一致),clockwise=false
时 svg 追加 scaleX(-1) 翻转扫描方向。
<template>
<div class="demo-col" style="gap: 18px; flex-wrap: wrap; flex-direction: row; align-items: flex-start">
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" />
<span class="demo-note">默认(受控 percent={{ percent }})</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" :size="80" :stroke-width="4" />
<span class="demo-note">size=80 strokeWidth=4</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" color="#A63D40" track-color="#EDE8E0" />
<span class="demo-note">单色 + trackColor</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" :color="['#2B4C7C', '#3A7D5A']" />
<span class="demo-note">双色渐变</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" :clockwise="false" :start-angle="90" />
<span class="demo-note">逆时针 + 起笔 3 点钟</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" :show-text="false" linecap="butt" />
<span class="demo-note">无文案 + linecap=butt</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" :format="format" label="数字化进度" />
<span class="demo-note">format 自定义文案</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhCircleProgress :model-value="percent" label="采集进度">
<span style="font-size: 12px">{{ percent }}/100</span>
</LhCircleProgress>
<span class="demo-note">默认插槽覆盖文案</span>
</div>
<div class="demo-row" style="gap: 12px; align-items: center">
<LhButton size="small" @click="dec">-10</LhButton>
<LhButton size="small" @click="inc">+10</LhButton>
</div>
</div>
</template>
<script>
export default {
data: () => ({
percent: 65,
}),
methods: {
format(v) {
return `${v} 成`
},
inc() {
this.percent = Math.min(this.percent + 10, 130)
},
dec() {
this.percent = Math.max(this.percent - 10, -20)
},
},
}
</script>
# 尺寸与描边
size 为环直径(px),strokeWidth 为描边宽度(px);半径取
(size - strokeWidth) / 2,描边不会越出视口:
<LhCircleProgress :model-value="70" :size="80" :stroke-width="4" />
# 颜色
color 支持单色字符串与渐变色数组(数组 ≥2 项时渲染 defs > linearGradient,
按等分偏移排布端点);trackColor 覆盖轨道色。两者均未传时走
lh-circle-progress 的令牌兜底(--lh-primary-color / 轨道灰):
<LhCircleProgress :model-value="70" color="#A63D40" track-color="#EDE8E0" />
<LhCircleProgress :model-value="70" :color="['#2B4C7C', '#3A7D5A']" />
# 方向与起笔角
startAngle(度,0 = 12 点钟,顺时针为正)决定起笔位置,内部换算为 svg
rotate 变换(SVG circle 默认从 3 点钟起笔);clockwise=false 追加
scaleX(-1) 整体翻转:
<LhCircleProgress :model-value="70" :clockwise="false" :start-angle="90" />
# 端点形状与文案
linecap 取 butt / round / square(默认 round)。showText=false
时根加 --no-text 修饰并隐藏环内文案;format 自定义默认文案
(入参为钳制后的百分比);默认插槽覆盖整段文案:
<LhCircleProgress :model-value="70" :format="(v) => `${v} 成`" />
<LhCircleProgress :model-value="70" label="采集进度">
<span style="font-size: 12px;">70/100</span>
</LhCircleProgress>
# Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| modelValue | 进度百分比 0-100(受控;越界钳制) | number | 0 |
| size | 环尺寸 px(直径) | number | 120 |
| strokeWidth | 描边宽度 px | number | 6 |
| color | 进度色:单色字符串或渐变色数组(数组 ≥2 项作 linearGradient 端点) | string \| string[] | — |
| trackColor | 轨道色(未传走令牌兜底) | string | — |
| clockwise | 顺时针(false 时 svg 追加 scaleX(-1)) | boolean | true |
| startAngle | 起始角度(度,0 = 12 点钟方向,顺时针为正) | number | 0 |
| showText | 展示默认百分比文案 | boolean | true |
| format | 文案格式化(入参为钳制后的百分比,默认取整百分号) | (percentage: number) => string | — |
| linecap | 描边端点形状 | 'butt' \| 'round' \| 'square' | 'round' |
| label | 无障碍可达名称(aria-label) | string | — |
| sx | sx 快速布局属性 | LhSxProps | — |
# Slots
| 插槽名 | 说明 | 作用域参数 |
|---|---|---|
| default | 覆盖环内默认文案(默认渲染 formatCircleText 结果) | — |
# 无障碍
根元素由 getCircleProgressAria 注入 role="progressbar"、
aria-valuemin="0"、aria-valuemax="100"、aria-valuenow(钳制后的百分比);
label 提供可达名称(无可见文字时必需)。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537