Progress进度条

展示操作的当前进度。

何时使用

在操作需要较长时间才能完成时,为用户显示该操作的当前进度和状态。

  • 当一个操作会打断当前界面,或者需要在后台运行,且耗时可能超过2秒时;
  • 当需要显示一个操作完成的百分比时。
  1. import { NzProgressModule } from 'ng-zorro-antd/progress';

代码演示Progress进度条 - 图2

Progress进度条 - 图3

进度条

标准的进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-line',
  4. template: `
  5. <nz-progress [nzPercent]="30"></nz-progress>
  6. <nz-progress [nzPercent]="50" nzStatus="active"></nz-progress>
  7. <nz-progress [nzPercent]="70" nzStatus="exception"></nz-progress>
  8. <nz-progress [nzPercent]="100"></nz-progress>
  9. <nz-progress [nzPercent]="50" [nzShowInfo]="false"></nz-progress>
  10. `
  11. })
  12. export class NzDemoProgressLineComponent {}

Progress进度条 - 图4

小型进度条

适合放在较狭窄的区域内。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-line-mini',
  4. template: `
  5. <div style="width: 170px;">
  6. <nz-progress [nzPercent]="30" nzSize="small"></nz-progress>
  7. <nz-progress [nzPercent]="50" nzSize="small" nzStatus="active"></nz-progress>
  8. <nz-progress [nzPercent]="70" nzSize="small" nzStatus="exception"></nz-progress>
  9. <nz-progress [nzPercent]="100" nzSize="small"></nz-progress>
  10. <nz-progress [nzPercent]="50" nzSize="small" [nzShowInfo]="false"></nz-progress>
  11. </div>
  12. `
  13. })
  14. export class NzDemoProgressLineMiniComponent {}

Progress进度条 - 图5

进度圈动态展示

会动的进度条才是好进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-circle-dynamic',
  4. template: `
  5. <nz-progress [nzPercent]="percent" nzType="circle"></nz-progress>
  6. <nz-button-group>
  7. <button nz-button (click)="decline()"><i nz-icon nzType="minus"></i></button>
  8. <button nz-button (click)="increase()"><i nz-icon nzType="plus"></i></button>
  9. </nz-button-group>
  10. `,
  11. styles: [
  12. `
  13. nz-progress {
  14. margin-right: 8px;
  15. }
  16. `
  17. ]
  18. })
  19. export class NzDemoProgressCircleDynamicComponent {
  20. percent = 0;
  21. increase(): void {
  22. this.percent = this.percent + 10;
  23. if (this.percent > 100) {
  24. this.percent = 100;
  25. }
  26. }
  27. decline(): void {
  28. this.percent = this.percent - 10;
  29. if (this.percent < 0) {
  30. this.percent = 0;
  31. }
  32. }
  33. }

Progress进度条 - 图6

自定义文字格式

nzFormat 属性指定格式。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-format',
  4. template: `
  5. <nz-progress [nzPercent]="75" nzType="circle" [nzFormat]="formatOne"></nz-progress>
  6. <nz-progress [nzPercent]="100" nzType="circle" [nzFormat]="formatTwo"></nz-progress>
  7. `,
  8. styles: [
  9. `
  10. nz-progress {
  11. margin-right: 8px;
  12. margin-bottom: 8px;
  13. display: inline-block;
  14. }
  15. `
  16. ]
  17. })
  18. export class NzDemoProgressFormatComponent {
  19. formatOne = (percent: number) => `${percent} Days`;
  20. formatTwo = () => `Done`;
  21. }

Progress进度条 - 图7

分段进度条

标准的进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-segment',
  4. template: `
  5. <nz-progress nz-tooltip nzTitle="3 done / 3 in progress / 4 to do" [nzPercent]="60" [nzSuccessPercent]="30"></nz-progress>
  6. <nz-progress
  7. nz-tooltip
  8. nzTitle="3 done / 3 in progress / 4 to do"
  9. nzType="circle"
  10. [nzPercent]="60"
  11. [nzSuccessPercent]="30"
  12. ></nz-progress>
  13. <nz-progress
  14. nz-tooltip
  15. nzTitle="3 done / 3 in progress / 4 to do"
  16. nzType="dashboard"
  17. [nzPercent]="60"
  18. [nzSuccessPercent]="30"
  19. ></nz-progress>
  20. `
  21. })
  22. export class NzDemoProgressSegmentComponent {}

Progress进度条 - 图8

自定义进度条渐变色

linear-gradient 的封装。推荐只传两种颜色。

  1. import { Component, ViewEncapsulation } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-gradient',
  4. template: `
  5. <nz-progress [nzPercent]="99.9" [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"></nz-progress>
  6. <nz-progress [nzPercent]="99.9" [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }" nzStatus="active"></nz-progress>
  7. <nz-progress nzType="circle" [nzPercent]="90" [nzStrokeColor]="{ '0%': '#108ee9', '50%': '#2db7f5', '100%': '#87d068' }"></nz-progress>
  8. <nz-progress nzType="dashboard" [nzPercent]="100" [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"></nz-progress>
  9. `,
  10. styles: [
  11. `
  12. .ant-progress {
  13. margin-right: 8px;
  14. margin-bottom: 8px;
  15. display: inline-block;
  16. }
  17. `
  18. ],
  19. encapsulation: ViewEncapsulation.None
  20. })
  21. export class NzDemoProgressGradientComponent {}

Progress进度条 - 图9

进度圈

圈形的进度。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-circle',
  4. template: `
  5. <nz-progress [nzPercent]="75" nzType="circle"></nz-progress>
  6. <nz-progress [nzPercent]="70" nzType="circle" nzStatus="exception"></nz-progress>
  7. <nz-progress [nzPercent]="100" nzType="circle"></nz-progress>
  8. `,
  9. styles: [
  10. `
  11. nz-progress {
  12. margin-right: 8px;
  13. margin-bottom: 8px;
  14. display: inline-block;
  15. }
  16. `
  17. ]
  18. })
  19. export class NzDemoProgressCircleComponent {}

Progress进度条 - 图10

小型进度圈

小一号的圈形进度。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-circle-mini',
  4. template: `
  5. <nz-progress [nzPercent]="75" nzType="circle" [nzWidth]="80"></nz-progress>
  6. <nz-progress [nzPercent]="70" nzType="circle" [nzWidth]="80" nzStatus="exception"></nz-progress>
  7. <nz-progress [nzPercent]="100" nzType="circle" [nzWidth]="80"></nz-progress>
  8. `,
  9. styles: [
  10. `
  11. nz-progress {
  12. margin-right: 8px;
  13. margin-bottom: 8px;
  14. display: inline-block;
  15. }
  16. `
  17. ]
  18. })
  19. export class NzDemoProgressCircleMiniComponent {}

Progress进度条 - 图11

动态展示

会动的进度条才是好进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-dynamic',
  4. template: `
  5. <nz-progress [nzPercent]="percent"></nz-progress>
  6. <nz-button-group>
  7. <button nz-button (click)="decline()"><i nz-icon nzType="minus"></i></button>
  8. <button nz-button (click)="increase()"><i nz-icon nzType="plus"></i></button>
  9. </nz-button-group>
  10. `
  11. })
  12. export class NzDemoProgressDynamicComponent {
  13. percent = 0;
  14. increase(): void {
  15. this.percent = this.percent + 10;
  16. if (this.percent > 100) {
  17. this.percent = 100;
  18. }
  19. }
  20. decline(): void {
  21. this.percent = this.percent - 10;
  22. if (this.percent < 0) {
  23. this.percent = 0;
  24. }
  25. }
  26. }

Progress进度条 - 图12

仪表盘

通过设置 nzType="dashboard",可以很方便地实现仪表盘样式的进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-dashboard',
  4. template: `
  5. <nz-progress [nzPercent]="75" nzType="dashboard"></nz-progress>
  6. `
  7. })
  8. export class NzDemoProgressDashboardComponent {}

Progress进度条 - 图13

圆角/方角边缘

通过设定 nzStrokeLinecap='square|round' 可以调整进度条边缘的形状。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-round',
  4. template: `
  5. <nz-progress nzStrokeLinecap="round" nzPercent="75"></nz-progress>
  6. <nz-progress nzStrokeLinecap="round" nzType="circle" nzPercent="75"></nz-progress>
  7. <nz-progress nzStrokeLinecap="square" nzType="dashboard" nzPercent="75"></nz-progress>
  8. `
  9. })
  10. export class NzDemoProgressRoundComponent {}

Progress进度条 - 图14

步骤进度条

带步骤的进度条。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-progress-step',
  4. template: `
  5. <nz-progress [nzPercent]="50" [nzSteps]="3" nzStrokeColor="#1890ff"></nz-progress>
  6. <nz-progress [nzPercent]="30" [nzSteps]="5" nzStrokeColor="#1890ff"></nz-progress>
  7. <nz-progress [nzPercent]="100" [nzSteps]="5" nzStrokeColor="#1890ff" nzSize="small"></nz-progress>
  8. `
  9. })
  10. export class NzDemoProgressStepComponent {}

API

各类型通用的属性。

属性说明类型默认值
[nzType]类型‘line’ | ‘circle’ | ‘dashboard’‘line’
[nzFormat]内容的模板函数(percent: number) => string | TemplateRef<{ $implicit: number }>percent => percent + ‘%’
[nzPercent]百分比number0
[nzShowInfo]是否显示进度数值或状态图标booleantrue
[nzStatus]状态‘success’ | ‘exception’ | ‘active’ | ‘normal’-
[nzStrokeLinecap]进度条端点形状‘round’ | ‘square’‘round’
[nzStrokeColor]进度条颜色,传入对象时为渐变string | { from: string; to: string: direction: string; [percent: string]: string }-
[nzSuccessPercent]已完成的分段百分比number0

nzType="line"

属性说明类型默认值
[nzStrokeWidth]进度条线的宽度,单位 pxnumber8
[nzSteps]进度条总共步数number-

nzType="circle"

属性说明类型默认值
[nzWidth]圆形进度条画布宽度,单位 pxnumber132
[nzStrokeWidth]圆形进度条线的宽度,单位是进度条画布宽度的百分比number6

nzType="dashboard"

属性说明类型默认值
[nzWidth]仪表盘进度条画布宽度,单位 pxnumber132
[nzStrokeWidth]仪表盘进度条线的宽度,单位是进度条画布宽度的百分比number6
[nzGapDegree]仪表盘进度条缺口角度,可取值 0 ~ 360number0
[nzGapPosition]仪表盘进度条缺口位置‘top’ | ‘right’ | ‘bottom’ | ‘left’‘top’