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] 自动钳制 | number | 0 |
| type | 形态 | "line" | "circle" | 'line' |
| status | 状态,normal 时达到 100 自动转为 success | "normal" | "success" | "warning" | "exception" | 'normal' |
| color | 进度条颜色:字符串或按百分比返回颜色的函数 | string | ((percentage: number) => string) | — |
| strokeWidth | 线条宽度 px(line 为高度,circle 为描边宽度) | number | 6 |
| width | 圆形模式画布宽度 px | number | 126 |
| showText | 是否展示文字 | boolean | true |
| format | 自定义文字格式化 | (percentage: number) => string | — |
| sx | sx 快速布局属性 | 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'