鸿蒙Harmony-Progress组件概述
1.1Progress组件概述
- 作用:显示操作或任务的进度,支持线性,环形,刻度等多种样式
- 适用场景:文件上传/下载、任务完成度、系统状态反馈等
2.1基础属性(参考官方文档)
[https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-progress-V5]:
2.1.1 参数详解
参数列表
参数名 |
类型 |
必填 |
默认值 |
说明 |
卡片能力 |
value |
number |
是 |
0 |
当前进度值。若设置 <0 则自动置为 0 ;若 >total 则置为 total 。 |
支持(API 9+) |
total |
number |
否 |
100 |
总进度长度。若设置 ≤0 则自动置为 100 。 |
支持(API 9+) |
type8+ |
ProgressType |
否 |
ProgressType.Linear |
进度条类型:
Linear (线性)/Ring (环形)/Eclipse (圆形)/Scale (刻度) |
支持(API 9+) |
style (deprecated) |
ProgressStyle |
否 |
ProgressStyle.Linear |
进度条样式(已废弃,建议使用 type 替代) |
支持(API 9+,但不再推荐使用) |
2.1.2关键说明
value
3.1使用示例
下面我通过组件封装的案例给大家演示
- 封装loading组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| @Component struct Loading { @State present: number = 10 private timeId: number | null = null
aboutToAppear(): void { if (this.timeId) { clearInterval(this.timeId) } this.timeId = setInterval(() => { if (this.present >= 100) { this.present = 0 } else { this.present++ } }, 30) }
aboutToDisappear(): void { if (this.timeId) { clearTimeout(this.timeId) this.timeId = null } }
build() { Column() { Progress({ value: this.present, type: ProgressType.Ring, total: 100 })
}
} }
export default Loading
|
- 展示页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import Loading from './Loading';
@Entry @Component struct Test3 { @State isShow: boolean = true private timerId: number | null = null
aboutToAppear(): void { this.timerId = setTimeout(() => { this.isShow = false
}, 3 * 1000) }
aboutToDisappear(): void { if (this.timerId) { clearTimeout(this.timerId) this.timerId = null } }
build() { Column() { if (this.isShow) { Loading() }
}.width('100%') .height('100%') } }
|
- 效果展示
