Progress进度条

展示操作的当前进度。

何时使用#

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

  • 当一个操作会打断当前界面,或者需要在后台运行,且耗时可能超过2秒时;
  • 当需要显示一个操作完成的百分比时。

单独引入此组件#

想要了解更多关于单独引入组件的内容,可以在快速上手页面进行查看。

import { NzProgressModule } from 'ng-zorro-antd/progress';

代码演示

30%
50%

标准的进度条。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-line',
  template: `
    <nz-progress [nzPercent]="30"></nz-progress>
    <nz-progress [nzPercent]="50" nzStatus="active"></nz-progress>
    <nz-progress [nzPercent]="70" nzStatus="exception"></nz-progress>
    <nz-progress [nzPercent]="100"></nz-progress>
    <nz-progress [nzPercent]="50" [nzShowInfo]="false"></nz-progress>
  `
})
export class NzDemoProgressLineComponent {}
30%
50%

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-line-mini',
  template: `
    <div style="width: 170px;">
      <nz-progress [nzPercent]="30" nzSize="small"></nz-progress>
      <nz-progress [nzPercent]="50" nzSize="small" nzStatus="active"></nz-progress>
      <nz-progress [nzPercent]="70" nzSize="small" nzStatus="exception"></nz-progress>
      <nz-progress [nzPercent]="100" nzSize="small"></nz-progress>
      <nz-progress [nzPercent]="50" nzSize="small" [nzShowInfo]="false"></nz-progress>
    </div>
  `
})
export class NzDemoProgressLineMiniComponent {}
0%

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-circle-dynamic',
  template: `
    <nz-progress [nzPercent]="percent" nzType="circle"></nz-progress>
    <nz-button-group>
      <button nz-button (click)="decline()"><i nz-icon nzType="minus"></i></button>
      <button nz-button (click)="increase()"><i nz-icon nzType="plus"></i></button>
    </nz-button-group>
  `,
  styles: [
    `
      nz-progress {
        margin-right: 8px;
      }
    `
  ]
})
export class NzDemoProgressCircleDynamicComponent {
  percent = 0;

  increase(): void {
    this.percent = this.percent + 10;
    if (this.percent > 100) {
      this.percent = 100;
    }
  }

  decline(): void {
    this.percent = this.percent - 10;
    if (this.percent < 0) {
      this.percent = 0;
    }
  }
}
75 Days
Done

nzFormat 属性指定格式。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-format',
  template: `
    <nz-progress [nzPercent]="75" nzType="circle" [nzFormat]="formatOne"></nz-progress>
    <nz-progress [nzPercent]="100" nzType="circle" [nzFormat]="formatTwo"></nz-progress>
  `,
  styles: [
    `
      nz-progress {
        margin-right: 8px;
        margin-bottom: 8px;
        display: inline-block;
      }
    `
  ]
})
export class NzDemoProgressFormatComponent {
  formatOne = (percent: number) => `${percent} Days`;
  formatTwo = () => `Done`;
}
60%
60%
60%

标准的进度条。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-segment',
  template: `
    <nz-progress
      nz-tooltip
      nzTitle="3 done / 3 in progress / 4 to do"
      [nzPercent]="60"
      [nzSuccessPercent]="30"
    ></nz-progress>
    <nz-progress
      nz-tooltip
      nzTitle="3 done / 3 in progress / 4 to do"
      nzType="circle"
      [nzPercent]="60"
      [nzSuccessPercent]="30"
    ></nz-progress>
    <nz-progress
      nz-tooltip
      nzTitle="3 done / 3 in progress / 4 to do"
      nzType="dashboard"
      [nzPercent]="60"
      [nzSuccessPercent]="30"
    ></nz-progress>
  `
})
export class NzDemoProgressSegmentComponent {}
99.9%
99.9%
90%

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

expand codeexpand code
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-gradient',
  template: `
    <nz-progress [nzPercent]="99.9" [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"></nz-progress>
    <nz-progress
      [nzPercent]="99.9"
      [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"
      nzStatus="active"
    ></nz-progress>
    <nz-progress
      nzType="circle"
      [nzPercent]="90"
      [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"
    ></nz-progress>
    <nz-progress
      nzType="dashboard"
      [nzPercent]="100"
      [nzStrokeColor]="{ '0%': '#108ee9', '100%': '#87d068' }"
    ></nz-progress>
  `,
  styles: [
    `
      .ant-progress {
        margin-right: 8px;
        margin-bottom: 8px;
        display: inline-block;
      }
    `
  ],
  encapsulation: ViewEncapsulation.None
})
export class NzDemoProgressGradientComponent {}
75%

圈形的进度。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-circle',
  template: `
    <nz-progress [nzPercent]="75" nzType="circle"></nz-progress>
    <nz-progress [nzPercent]="70" nzType="circle" nzStatus="exception"></nz-progress>
    <nz-progress [nzPercent]="100" nzType="circle"></nz-progress>
  `,
  styles: [
    `
      nz-progress {
        margin-right: 8px;
        margin-bottom: 8px;
        display: inline-block;
      }
    `
  ]
})
export class NzDemoProgressCircleComponent {}
75%

小一号的圈形进度。

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-circle-mini',
  template: `
    <nz-progress [nzPercent]="75" nzType="circle" [nzWidth]="80"></nz-progress>
    <nz-progress [nzPercent]="70" nzType="circle" [nzWidth]="80" nzStatus="exception"></nz-progress>
    <nz-progress [nzPercent]="100" nzType="circle" [nzWidth]="80"></nz-progress>
  `,
  styles: [
    `
      nz-progress {
        margin-right: 8px;
        margin-bottom: 8px;
        display: inline-block;
      }
    `
  ]
})
export class NzDemoProgressCircleMiniComponent {}
0%

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-dynamic',
  template: `
    <nz-progress [nzPercent]="percent"></nz-progress>
    <nz-button-group>
      <button nz-button (click)="decline()"><i nz-icon nzType="minus"></i></button>
      <button nz-button (click)="increase()"><i nz-icon nzType="plus"></i></button>
    </nz-button-group>
  `
})
export class NzDemoProgressDynamicComponent {
  percent = 0;

  increase(): void {
    this.percent = this.percent + 10;
    if (this.percent > 100) {
      this.percent = 100;
    }
  }

  decline(): void {
    this.percent = this.percent - 10;
    if (this.percent < 0) {
      this.percent = 0;
    }
  }
}
75%

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-dashboard',
  template: `
    <nz-progress [nzPercent]="75" nzType="dashboard"></nz-progress>
  `
})
export class NzDemoProgressDashboardComponent {}
75%
75%
75%

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

expand codeexpand code
import { Component } from '@angular/core';

@Component({
  selector: 'nz-demo-progress-round',
  template: `
    <nz-progress nzStrokeLinecap="round" nzPercent="75"></nz-progress>
    <nz-progress nzStrokeLinecap="round" nzType="circle" nzPercent="75"></nz-progress>
    <nz-progress nzStrokeLinecap="square" nzType="dashboard" nzPercent="75"></nz-progress>
  `
})
export class NzDemoProgressRoundComponent {}

API#

各类型通用的属性。

属性说明类型默认值
[nzType]类型'line' | 'circle' | 'dashboard''line'
[nzFormat]内容的模板函数(percent: number) => stringpercent => 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

nzType="circle"#

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

nzType="dashboard"#

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