Progress进度条 - 图1

Progress 进度条

展示操作的当前进度。

何时使用

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

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

    代码演示

Progress进度条 - 图2

进度条

标准的进度条。

  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" :show-info="false" />
  8. </div>
  9. </template>

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="percent" />
  4. <a-button-group>
  5. <a-button icon="minus" @click="decline" />
  6. <a-button icon="plus" @click="increase" />
  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进度条 - 图5

动态展示

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

  1. <template>
  2. <div>
  3. <a-progress :percent="percent" />
  4. <a-button-group>
  5. <a-button icon="minus" @click="decline" />
  6. <a-button icon="plus" @click="increase" />
  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

分段进度条

标准的进度条。

  1. <template>
  2. <div>
  3. <a-tooltip title="3 done / 3 in progress / 4 to do">
  4. <a-progress :percent="60" :success-percent="30" />
  5. </a-tooltip>
  6. <a-tooltip title="3 done / 3 in progress / 4 to do">
  7. <a-progress :percent="60" :success-percent="30" type="circle" />
  8. </a-tooltip>
  9. <a-tooltip title="3 done / 3 in progress / 4 to do">
  10. <a-progress :percent="60" :success-percent="30" type="dashboard" />
  11. </a-tooltip>
  12. </div>
  13. </template>

Progress进度条 - 图7

自定义进度条渐变色

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

  1. <template>
  2. <div>
  3. <a-progress
  4. :stroke-color="{
  5. '0%': '#108ee9',
  6. '100%': '#87d068',
  7. }"
  8. :percent="99.9"
  9. />
  10. <a-progress
  11. :stroke-color="{
  12. from: '#108ee9',
  13. to: '#87d068',
  14. }"
  15. :percent="99.9"
  16. status="active"
  17. />
  18. <a-progress
  19. type="circle"
  20. :stroke-color="{
  21. '0%': '#108ee9',
  22. '100%': '#87d068',
  23. }"
  24. :percent="90"
  25. />
  26. <a-progress
  27. type="circle"
  28. :stroke-color="{
  29. '0%': '#108ee9',
  30. '100%': '#87d068',
  31. }"
  32. :percent="100"
  33. />
  34. </div>
  35. </template>

Progress进度条 - 图8

进度圈

圈形的进度。

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

小型进度圈

小一号的圈形进度。

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

自定义文字格式

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. <a-progress type="circle" :percent="75">
  6. <template #format="percent">
  7. <span style="color: red">{{ percent }}</span>
  8. </template>
  9. </a-progress>
  10. </div>
  11. </template>
  12. <style scoped>
  13. div.ant-progress-circle,
  14. div.ant-progress-line {
  15. margin-right: 8px;
  16. margin-bottom: 8px;
  17. }
  18. </style>

Progress进度条 - 图11

仪表盘

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

圆角/方角边缘

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

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

API

各类型共用的属性。

属性说明类型默认值
type类型,可选 line circle dashboardstringline
format内容的模板函数function(percent, successPercent) | v-slot:format=”percent, successPercent”percent => percent + ‘%’
percent百分比number0
showInfo是否显示进度数值或状态图标booleantrue
status状态,可选:success exception normal active(仅限 line)string-
strokeLinecapEnum{ ‘round’, ‘square’ }round
strokeColor进度条的色彩string-
successPercent已完成的分段百分比number0

type="line"

属性说明类型默认值版本
strokeWidth进度条线的宽度,单位 pxnumber10
strokeColor进度条的色彩,传入 object 时为渐变string | { from: string; to: string; direction: string }-1.5.0

type="circle"

属性说明类型默认值版本
width圆形进度条画布宽度,单位 pxnumber132
strokeWidth圆形进度条线的宽度,单位是进度条画布宽度的百分比number6
strokeColor圆形进度条线的色彩,传入 object 时为渐变string | object-1.5.0

type="dashboard"

属性说明类型默认值
width仪表盘进度条画布宽度,单位 pxnumber132
strokeWidth仪表盘进度条线的宽度,单位是进度条画布宽度的百分比number6
gapDegree仪表盘进度条缺口角度,可取值 0 ~ 360number0
gapPosition仪表盘进度条缺口位置Enum{ ‘top’, ‘bottom’, ‘left’, ‘right’ }top