Progress 进度条
展示有明确总量的任务进度,支持状态色、均匀色标和自定义文字。
引入
uni-app 配置 easycom 后使用 <hui-progress>。公开类型和函数从 @nscode/handy-uni 导入;普通 Vue 3 安装 @nscode/handy-uni/web 预览插件。
示例
示例可独立运行;交互结果直接显示在页面。
vue
<template>
<view>
<hui-space direction="vertical" fill>
<hui-progress
custom-class="hui-space__item"
:percentage="value"
label="上传进度 / Upload progress"
/>
<hui-progress
custom-class="hui-space__item"
:percentage="value"
:color="['#1d4ed8', '#15803d']"
text-inside
:stroke-width="20"
/>
<hui-progress
v-for="status in statuses"
:key="status"
custom-class="hui-space__item"
:percentage="65"
:status="status"
/>
<hui-progress custom-class="hui-space__item" :percentage="value" :show-text="false" />
<hui-progress
custom-class="hui-space__item"
:percentage="value"
:format="(p) => p + ' / 100'"
/>
<hui-button custom-class="hui-space__item" @click="value = (value + 10) % 110"
>推进 / Advance</hui-button
>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(30)
const statuses = ['success', 'warning', 'exception'] as const
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
percentage | number | 0 | 0~100;超出按边界截断,NaN 按 0 并警告 |
status | ProgressStatus | — | 状态色;color 优先 |
strokeWidth | number | 6 | 线高,px |
textInside | boolean | false | 文字放进条里;线高小于 16 时按 16 画并警告 |
showText | boolean | true | 显示进度文字。 |
format | (percentage: number) => string | — | 文字格式;不传为 ${percentage}% |
color | ProgressColor | — | 字符串为固定色;数组为均匀分布在 0~100 的色标并逐段插值;函数接收截断后的进度。 |
trackColor | string | — | 轨道色;不传用 --hui-progress-track-bg |
duration | number | 300 | 宽度变化的过渡时长,ms;0 不动画 |
label | string | — | 读屏名称(“上传进度”);不传时只读数值 |
根节点类名和样式使用 customClass、customStyle。尺寸数字按 px,时长除明确说明外按 ms。
Events
无。
Slots
| 插槽 | 作用域 |
|---|---|
default | { percentage, status } |
方法
无。
类型
ProgressStatus、ProgressColorFn、ProgressColor、ProgressProps、ProgressEmits.
主题变量
通过祖先样式或组件的 customStyle 覆盖:
| 变量 | 默认值 | 说明 |
|---|---|---|
--hui-progress-inside-color | var(--hui-color-white, #fff) | textInside 文字能完整放进进度条时的颜色。 |
--hui-progress-text-color | var(--hui-text-color) | 外部文字颜色;进度条过短、条内文字贴到轨道左端时也使用此色。 |
平台说明
基于共享平台组件实现 H5、微信小程序、App-vue 与普通 Vue 3 Web。单元测试不代替设备验收;触摸、读屏、页面失活和原生组件表现按冒烟清单逐端核对。
设备冒烟清单.