• Progress进度条
    • 何时使用
    • 单独引入此组件
    • 代码演示
    • API
      • nz-progresscomponent

    Progress进度条

    展示操作的当前进度。

    何时使用

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

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

    单独引入此组件

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

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

    代码演示

    Progress进度条 - 图1

    进度条

    标准的进度条。

    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进度条 - 图2

    小型进度条

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

    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进度条 - 图3

    进度圈动态展示

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

    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进度条 - 图4

    自定义文字格式

    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进度条 - 图5

    分段进度条

    标准的进度条。

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

    Progress进度条 - 图6

    进度圈

    圈形的进度。

    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进度条 - 图7

    小型进度圈

    小一号的圈形进度。

    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进度条 - 图8

    动态展示

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

    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进度条 - 图9

    仪表盘

    通过设置 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进度条 - 图10

    圆角/方角边缘

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

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

    API

    nz-progresscomponent

    属性说明类型默认值
    [nzFormat]内容的模板函数(percent: number) => stringpercent => percent + '%'
    [nzGapDegree](nzType=circle)圆形进度条缺口角度,可取值 0 ~ 360number0
    [nzGapPosition](nzType=circle)圆形进度条缺口位置'top' | 'right' | 'bottom' | 'left''top'
    [nzPercent]百分比number0
    [nzShowInfo]是否显示进度数值或状态图标booleantrue
    [nzStatus]状态'success' | 'exception' | 'active' | 'normal'-
    [nzStrokeWidth](nzType=line)进度条线的宽度,单位 pxnumber8
    [nzStrokeWidth](nzType=circle)圆形进度条线的宽度,单位是进度条画布宽度的百分比number6
    [nzType]类型'line' | 'circle' | 'dashboard''line'
    [nzWidth](nzType=circle)圆形进度条画布宽度,单位 pxnumber132
    [nzStrokeLinecap]进度条端点形状'round' | 'square''round'
    [nzStrokeColor]进度条颜色string-