Skip to content
API 风格:

Progress 进度条 ​

LhProgress 用于展示任务或容量的完成进度,支持线形与圆形两种形态,可自定义颜色与文字。

基础用法 ​

线形进度条
60%
vue
<script setup lang="ts">
</script>

<template>
  <LhProgress :percentage="60" />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhProgress :percentage="60" />
</template>

状态 ​

normal / success / warning / exception,达到 100 自动 success
100%
80%
40%
vue
<script setup lang="ts">
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px">
    <LhProgress :percentage="100" />
    <LhProgress :percentage="80" status="warning" />
    <LhProgress :percentage="40" status="exception" />
  </div>
</template>
vue
<script>
export default {}
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px">
    <LhProgress :percentage="100" />
    <LhProgress :percentage="80" status="warning" />
    <LhProgress :percentage="40" status="exception" />
  </div>
</template>

自定义颜色与文字 ​

color 支持字符串与函数,format 自定义文案
55%
70 分
vue
<script setup lang="ts">
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px">
    <LhProgress :percentage="55" color="#B8860B" />
    <LhProgress
      :percentage="70"
      :color="(p: number) => `hsl(${p * 1.2}, 60%, 45%)`"
      :format="(p: number) => `${p} 分`"
    />
  </div>
</template>
vue
<script>
export default {}
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px">
    <LhProgress :percentage="55" color="#B8860B" />
    <LhProgress
      :percentage="70"
      :color="(p: number) => `hsl(${p * 1.2}, 60%, 45%)`"
      :format="(p: number) => `${p} 分`"
    />
  </div>
</template>

圆形进度 ​

type 设为 circle
75%
100%
vue
<script setup lang="ts">
</script>

<template>
  <div style="display: flex; align-items: center; gap: 24px">
    <LhProgress type="circle" :percentage="75" />
    <LhProgress type="circle" :percentage="100" :width="100" :stroke-width="8" />
  </div>
</template>
vue
<script>
export default {}
</script>

<template>
  <div style="display: flex; align-items: center; gap: 24px">
    <LhProgress type="circle" :percentage="75" />
    <LhProgress type="circle" :percentage="100" :width="100" :stroke-width="8" />
  </div>
</template>

不展示文字 ​

showText 设为 false
vue
<script setup lang="ts">
</script>

<template>
  <LhProgress :percentage="45" :show-text="false" />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhProgress :percentage="45" :show-text="false" />
</template>

API ​

Props ​

属性说明类型默认值
percentage进度百分比,超出 [0, 100] 自动钳制number0
type形态"line" | "circle"'line'
status状态,normal 时达到 100 自动转为 success"normal" | "success" | "warning" | "exception"'normal'
color进度条颜色:字符串或按百分比返回颜色的函数string | ((percentage: number) => string)—
strokeWidth线条宽度 px(line 为高度,circle 为描边宽度)number6
width圆形模式画布宽度 pxnumber126
showText是否展示文字booleantrue
format自定义文字格式化(percentage: number) => string—
sxsx 快速布局属性LhSxProps—

Slots ​

插槽名说明作用域
text自定义文字内容{ percentage }

无障碍 ​

  • 根元素带 role="progressbar" 与 aria-valuemin / aria-valuemax / aria-valuenow,对齐 WAI-ARIA progressbar 模式
  • aria-valuetext 同步可见文案:默认为百分比,传 format 时播报格式化后的文本(如「42 分」)
  • 钳制后的值同步到 aria-valuenow,不会出现超出范围的播报

类型定义 ​

本组件对外导出的 TypeScript 类型结构如下(自动提取自 packages/components/progress/src/types.ts 与 @lh-ui/share/core/* 源码,点击各条目展开查看完整定义;属性说明见上方 Props 表):

LhProgressProps
ts
export interface LhProgressProps {
  /** 进度百分比 0-100(超出会自动钳制) */
  percentage: number
  type?: LhProgressType
  status?: LhProgressStatus
  /** 进度条颜色:字符串或按百分比返回颜色的函数 */
  color?: string | ((percentage: number) => string)
  /** 线条宽度 px(line 为高度,circle 为描边宽度) */
  strokeWidth?: number
  /** 圆形模式画布宽度 px */
  width?: number
  showText?: boolean
  /** 自定义文字格式化 */
  format?: (percentage: number) => string
  /** sx 快速布局属性 */
  sx?: LhSxProps
}
LhProgressType (来自 @lh-ui/share/core/progress)
ts
export type LhProgressType = 'line' | 'circle'
LhProgressStatus (来自 @lh-ui/share/core/progress)
ts
export type LhProgressStatus = 'normal' | 'success' | 'warning' | 'exception'