Progress 进度条

展示操作的当前进度。

何时使用

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

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

代码演示

Progress进度条 - 图1

进度条

标准的进度条。

  1. <template>
  2. <div>
  3. <a-progress :percent="30" />
  4. <a-progress :percent="50" status="active" />
  5. <a-progress :percent="70" status="exception" />
  6. <a-progress :percent="100" />
  7. <a-progress :percent="50" :showInfo="false" />
  8. </div>
  9. </template>

Progress进度条 - 图2

进度圈

圈形的进度。

  1. <template>
  2. <div>
  3. <a-progress type="circle" :percent="75" />
  4. <a-progress type="circle" :percent="70" status="exception" />
  5. <a-progress type="circle" :percent="100" />
  6. </div>
  7. </template>
  8. <style scoped>
  9. .ant-progress-circle-wrap,
  10. .ant-progress-line-wrap {
  11. margin-right: 8px;
  12. margin-bottom: 5px;
  13. }
  14. </style>

Progress进度条 - 图3

小型进度条

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

  1. <template>
  2. <div style="width: 170px">
  3. <a-progress :percent="30" size="small" />
  4. <a-progress :percent="50" size="small" status="active" />
  5. <a-progress :percent="70" size="small" status="exception" />
  6. <a-progress :percent="100" size="small" />
  7. </div>
  8. </template>

Progress进度条 - 图4

小型进度圈

小一号的圈形进度。

  1. <template>
  2. <div>
  3. <a-progress type="circle" :percent="30" :width="80" />
  4. <a-progress type="circle" :percent="70" :width="80" status="exception" />
  5. <a-progress type="circle" :percent="100" :width="80" />
  6. </div>
  7. </template>
  8. <style scoped>
  9. .ant-progress-circle-wrap,
  10. .ant-progress-line-wrap {
  11. margin-right: 8px;
  12. margin-bottom: 5px;
  13. }
  14. </style>

Progress进度条 - 图5

进度圈动态展示

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

  1. <template>
  2. <div>
  3. <a-progress type="circle" :percent="percent" />
  4. <a-button-group>
  5. <a-button @click="decline" icon="minus" />
  6. <a-button @click="increase" icon="plus" />
  7. </a-button-group>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data () {
  13. return {
  14. percent: 0,
  15. }
  16. },
  17. methods: {
  18. increase() {
  19. let percent = this.percent + 10;
  20. if (percent > 100) {
  21. percent = 100;
  22. }
  23. this.percent = percent
  24. },
  25. decline() {
  26. let percent = this.percent - 10;
  27. if (percent < 0) {
  28. percent = 0;
  29. }
  30. this.percent = percent
  31. },
  32. },
  33. }
  34. </script>

Progress进度条 - 图6

自定义文字格式

format 属性指定格式。

  1. <template>
  2. <div>
  3. <a-progress type="circle" :percent="75" :format="percent => `${percent} Days`"/>
  4. <a-progress type="circle" :percent="100" :format="() => 'Done'" />
  5. </div>
  6. </template>
  7. <style scoped>
  8. div.ant-progress-circle,
  9. div.ant-progress-line {
  10. margin-right: 8px;
  11. margin-bottom: 8px;
  12. }
  13. </style>

Progress进度条 - 图7

动态展示

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

  1. <template>
  2. <div>
  3. <a-progress :percent="percent" />
  4. <a-button-group>
  5. <a-button @click="decline" icon="minus" />
  6. <a-button @click="increase" icon="plus" />
  7. </a-button-group>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data () {
  13. return {
  14. percent: 0,
  15. }
  16. },
  17. methods: {
  18. increase() {
  19. let percent = this.percent + 10;
  20. if (percent > 100) {
  21. percent = 100;
  22. }
  23. this.percent = percent
  24. },
  25. decline() {
  26. let percent = this.percent - 10;
  27. if (percent < 0) {
  28. percent = 0;
  29. }
  30. this.percent = percent
  31. },
  32. },
  33. }
  34. </script>

Progress进度条 - 图8

仪表盘

By setting type=dashboard, you can get a dashboard style of progress easily.

  1. <template>
  2. <div>
  3. <a-progress type="dashboard" :percent="75" />
  4. </div>
  5. </template>

Progress进度条 - 图9

分段进度条

标准的进度条。

  1. <template>
  2. <a-tooltip title="3 done / 3 in progress / 4 to do">
  3. <a-progress :percent="60" :successPercent="30" />
  4. </a-tooltip>
  5. </template>

Progress进度条 - 图10

圆角/方角边缘

strokeLinecap="square|round" 可以调整进度条边缘的形状。

  1. <template>
  2. <div>
  3. <a-progress strokeLinecap="square" :percent="75" />
  4. <a-progress strokeLinecap="square" :percent="75" type="circle" />
  5. <a-progress strokeLinecap="square" :percent="75" type="dashboard" />
  6. </div>
  7. </template>

API

属性说明类型默认值
format内容的模板函数function(percent, successPercent)percent => percent + '%'
gapDegree (type=circle)圆形进度条缺口角度,可取值 0 ~ 360number0
gapPosition (type=circle)圆形进度条缺口位置Enum{ 'top', 'bottom', 'left', 'right' }top
percent百分比number0
showInfo是否显示进度数值或状态图标booleantrue
status状态,可选:normal success exception activestringnormal
strokeWidth (type=line)进度条线的宽度,单位 pxnumber10
strokeWidth (type=circle)圆形进度条线的宽度,单位是进度条画布宽度的百分比number6
strokeLinecapEnum{ 'round', 'square' }round
strokeColor进度条的色彩string-
successPercent已完成的分段百分比,type="line" 时有效number0
type类型,可选 line circle dashboardstringline
width (type=circle)圆形进度条画布宽度,单位 pxnumber120