CircleProgress 進度環
環形進度元件:canvas 2d 繪製軌道圓與進度弧(drawCircleTrack / drawCircleArc,share core 統一收口,web 與小程式同構),文字以絕對定位 view 覆蓋於畫布之上。服務任務進度、載入占比、評分占比等場景。
平台差異(登記):本端為 canvas 2d 形態——小程式模板不支援 SVG(share circle-progress 的 SVG 樣式面向 web 端),本端以
<canvas type="2d">消費同一份 share core 繪製純函式;幾何(半徑 / 掃角 / 逆時針換算)與顏色歸一、文案格式化全部復用 share core,端內只做 canvas 取上下文與重繪排程。元件無事件、純受控。
基礎用法
vue
<template>
<lh-circle-progress :model-value="40" />
<lh-circle-progress :model-value="70" :size="140" :stroke-width="12" />
</template>自訂顏色與漸層
color 支援單色字串或色陣列;陣列 ≥2 項時按陣列順序作為線性漸層端點。trackColor 未傳時取軌道令牌的兜底色:
vue
<lh-circle-progress :model-value="70" color="#B87800" track-color="#F0EBE2" />
<lh-circle-progress :model-value="80" :color="['#2B4C7C', '#C4A35A']" />
<lh-circle-progress :model-value="80" :color="['#5B8C5A', '#C4A35A', '#B23A3A']" />逆時針與起始角度
clockwise 預設 true(順時針);startAngle 以 12 點鐘方向為 0 度、順時針為正:
vue
<lh-circle-progress :model-value="55" :clockwise="false" />
<lh-circle-progress :model-value="55" :start-angle="90" />
<lh-circle-progress :model-value="55" :start-angle="135" :clockwise="false" />自訂文案
預設文案為取整百分比;format 覆寫格式化,預設 slot 覆寫整段文案,showText=false 關閉文案(根節點追加 lh-circle-progress--no-text):
vue
<lh-circle-progress :model-value="42" :format="(v: number) => `${v} 分`" />
<lh-circle-progress :model-value="100">完成</lh-circle-progress>
<lh-circle-progress :model-value="30" :show-text="false" />Props
| 屬性 | 說明 | 型別 | 預設值 |
|---|---|---|---|
| modelValue | 進度百分比 0-100(受控,超出自動鉗制) | number | 0 |
| size | 環尺寸 px(直徑,canvas 畫布寬高) | number | 120 |
| strokeWidth | 描邊寬度 px | number | 6 |
| color | 進度色:單色或漸層色陣列(≥2 項作線性漸層端點) | `string | string[]` |
| trackColor | 軌道色(未傳取令牌兜底色) | string | 停用色兜底 |
| clockwise | 順時針(false 為逆時針描畫) | boolean | true |
| startAngle | 起始角度(度,0 = 12 點鐘方向,順時針為正) | number | 0 |
| showText | 顯示預設百分比文案 | boolean | true |
| format | 文案格式化(預設取整百分比) | (v: number) => string | — |
| linecap | 描邊端點形狀 | `'butt' | 'round' |
| label | 無障碍可達名稱 | string | — |
| customClass | 自訂類名(透傳到根節點) | string | — |
| sx | sx 快速佈局屬性 | LhSxProps | — |
無障碍
根節點帶有 role="progressbar" 與 aria-valuemin/max/now 值域語義;label 提供可達名稱(如「上傳進度」),modelValue 超出 0-100 時先鉗制再播報。

