Skip to content

Progress 进度条

用于展示操作的当前进度。

组件类型

基本用法

设置百分比 percentage

html
<wd-progress :percentage="50" />

内置百分比

通过 percent-position 配置百分比显示在进度条内部,并设置对齐方式。

html
<wd-progress :percentage="50" :percent-position="{ type: 'inner', align: 'center' }" />
<wd-progress :percentage="50" status="success" :percent-position="{ type: 'inner', align: 'right' }" />
<wd-progress :percentage="50" status="danger" :percent-position="{ type: 'inner', align: 'left' }" />

组件状态

状态

设置 status,告知用户当前状态和预期。

html
<wd-progress :percentage="50" status="success" hide-text />
<wd-progress :percentage="50" status="danger" hide-text />
<wd-progress :percentage="50" status="warning" hide-text />

组件样式

隐藏进度文字

设置 hide-text 隐藏进度文字。

html
<wd-progress :percentage="50" hide-text />

修改颜色

设置 color 修改进度条颜色。

html
<wd-progress :percentage="50" color="var(--wot-color-theme, #0083ff)" />
<wd-progress :percentage="50" color="var(--wot-color-success, #00c740)" />
<wd-progress :percentage="50" color="var(--wot-color-warning, #ffb300)" />

颜色数组

color 也可以设置为颜色数组或 ProgressColor[]。当传入字符串数组时,组件会自动计算每段颜色对应的进度边界。

html
<wd-progress :percentage="50" :color="['#00c740', '#ffb300', '#e2231a', '#0083ff']" />
<wd-progress :percentage="50" :color="colorObject" />
ts
import type { ProgressColor } from '@/uni_modules/wot-ui/components/wd-progress/types'

const colorObject: ProgressColor[] = [
  {
    color: 'yellow',
    percentage: 30
  },
  {
    color: 'red',
    percentage: 60
  },
  {
    color: 'blue',
    percentage: 80
  },
  {
    color: 'black',
    percentage: 90
  }
]

特殊样式

动态控制

通过修改 percentage 绑定值,可以实现动态进度控制。

html
<wd-progress :percentage="percentage" />
<wd-button type="danger" size="small" @click="reduce">-10</wd-button>
<wd-button type="success" size="small" @click="add">+10</wd-button>
ts
const percentage = ref(50)

function add() {
  percentage.value = Math.min(percentage.value + 10, 100)
}

function reduce() {
  percentage.value = Math.max(percentage.value - 10, 0)
}

Attributes

参数说明类型默认值
percentage进度数值,最大值为 100number0
hide-text是否隐藏进度文字booleanfalse
color进度条颜色,可选值为 stringstring[]ProgressColor[]string | string[] | ProgressColor[]-
status进度条状态,可选值为 successdangerwarningstring-
duration进度增加 1% 所需毫秒数number30
percent-position百分比显示位置配置,type 可选 innerouteralign 可选 leftcenterrightPercentPosition{ align: 'right', type: 'outer' }
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

ProgressColor

参数说明类型默认值
color颜色值string-
percentage颜色生效的进度阈值number-

PercentPosition

参数说明类型默认值
type百分比显示位置,可选值为 innerouterstring'outer'
align百分比文本对齐方式,可选值为 leftcenterrightstring'right'

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-progress-bg$filled-content进度条底色
--wot-progress-danger-color$danger-maindanger 进度色
--wot-progress-success-color$success-mainsuccess 进度色
--wot-progress-warning-color$warning-mainwarning 进度色
--wot-progress-color$primary-6默认进度色
--wot-progress-bar-height$n-8外部文案模式进度条高度
--wot-progress-height$n-18内部文案模式组件高度
--wot-progress-label-color$text-main外部文案颜色
--wot-progress-label-width$n-34外部文案宽度
--wot-progress-label-margin-left$spacing-tight外部文案左侧间距
--wot-progress-inner-label-color$text-white内部文案颜色
--wot-progress-inner-zero-bg$primary-2内部 zero 态背景色
--wot-progress-inner-zero-color$text-secondary内部 zero 态文字颜色
--wot-progress-inner-padding$padding-zero $padding-tight内部文案内边距
--wot-progress-label-font-size$typography-label-size-large文案字号
--wot-progress-label-line-height$typography-label-line--height-size-large文案行高
--wot-progress-icon-size$n-18图标字号
--wot-progress-radius$radius-radius-full进度条圆角

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.