# 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