Skip to content

xtf-progress

组件说明

xtf-progress 是进度条组件,用于展示任务完成度或数据占比。支持 line(线性)/ circle(环形)/ dashboard(仪表盘)三种形态、渐变/玻璃/辉光/霓虹等变体、条纹/不定态/步骤分段等表现,配合 active 动效、format 自定义文案和 steps 步骤条能力,是数据展示层反馈进度的核心组件。


基础用法

1. 最简示例

通过 percentage 设置进度值(0~100),theme 控制主题色:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="30" />
    <xtf-progress :percentage="60" theme="success" />
    <xtf-progress :percentage="85" theme="warning" />
  </view>
</template>

2. 标题与描述

通过 title / desc 展示进度标题和描述,通过 show-text 控制百分比文字显隐:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="70" title="课程进度" desc="已完成 14/20 节" />
    <xtf-progress
      :percentage="45"
      title="上传进度"
      desc="正在上传中..."
      theme="info"
      :show-text="false"
    />
  </view>
</template>

3. 环形与仪表盘

通过 type="circle" / type="dashboard" 切换形态:

vue
<template>
  <view style="display: flex; gap: 64rpx; align-items: center; padding: 32rpx">
    <xtf-progress type="circle" :percentage="75" />
    <xtf-progress type="dashboard" :percentage="60" theme="success" />
    <xtf-progress type="circle" :percentage="90" theme="danger" :note="'风险'" />
  </view>
</template>

4. 条纹与不定态

通过 striped 开启条纹动画,通过 indeterminate 显示无限加载:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="50" striped />
    <xtf-progress indeterminate :show-text="false" />
  </view>
</template>

5. 步骤进度

通过 steps 将线性进度转为 N 段步骤条:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="60" :steps="5" title="注册进度" />
    <xtf-progress :percentage="40" :steps="4" theme="success" title="实名认证" />
  </view>
</template>

6. 自定义文案与激活动效

通过 format 自定义百分比文案,通过 active 开启从 0 到目标值的激活动画:

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="80" :format="formatText" />
    <xtf-progress :percentage="100" active title="激活动画" desc="加载完成后展示" />
  </view>
</template>

<script>
export default {
  methods: {
    formatText(percentage) {
      // percentage 为当前显示值
      return percentage === 100 ? '已完成' : percentage + '%'
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
typeString'line'形态:'line' / 'circle' / 'dashboard'切换形态
percentageString | Number0进度值(0~100)设置进度
percentString | Numberundefined进度值别名(优先于 percentage兼容命名
themeString'primary'主题色:'primary' / 'success' / 'warning' / 'danger' / 'info'切换颜色
variantString'gradient'变体:'gradient' / 'default' / 'glass' / 'glow' / 'neon'切换视觉形态
titleString''标题展示标题
descString''描述展示描述
noteString''环形内部的备注文字(优先于 desc环形标注
showTextBooleantrue是否显示百分比文字显隐文案
insideTextBooleanfalse百分比文字是否显示在进度条内部线性内嵌
stripedBooleanfalse是否显示条纹视觉强调
indeterminateBooleanfalse不定态无限加载未知进度
sizeString'md'尺寸:'sm' / 'md' / 'lg'控制粗细/直径
strokeWidthString | Number''自定义描边宽度精确控制
trackColorString''自定义轨道颜色精确控制轨道
stepsString | Number0步骤分段数,0 为连续进度步骤条
indicatorBooleanfalse仅声明的兼容属性,当前实现未消费,传入不会显示指示器无实际展示效果
colorString''自定义激活色精确控制颜色
activeColorString''自定义激活色(同 color精确控制颜色
activeBooleanfalse是否激活从 0 到目标值的动画加载动效
activeModeString'backwards'激活动画模式:'backwards'动效模式
showInfoBooleanundefined显示文案(show-text 的兼容别名);传入时优先于 showText显隐文案
formatFunctionnull自定义百分比文案,(percentage: Number) => String自定义文案
customClassString''自定义类名样式覆盖
customStyleString | Object''自定义样式动态样式覆盖

事件

xtf-progress 为纯展示组件,不对外抛出事件。如需在进度变化时做业务处理,可通过父级 v-model 绑定数值并配合 watch 实现。

示例:监听进度变化

vue
<template>
  <view style="display: flex; flex-direction: column; gap: 32rpx; padding: 32rpx">
    <xtf-progress :percentage="progress" title="下载进度" />
    <xtf-button label="开始下载" :loading="downloading" @click="startDownload" />
  </view>
</template>

<script>
export default {
  data() {
    return { progress: 0, downloading: false }
  },
  watch: {
    progress(val) {
      console.log('进度变化:', val + '%')
      if (val >= 100) {
        this.downloading = false
        uni.showToast({ title: '下载完成', icon: 'success' })
      }
    }
  },
  methods: {
    startDownload() {
      this.downloading = true
      this.progress = 0
      const timer = setInterval(() => {
        this.progress += 10
        if (this.progress >= 100) {
          clearInterval(timer)
        }
      }, 400)
    }
  }
}
</script>

插槽

xtf-progress 暂未开放插槽,所有内容均通过属性配置。


主题说明

  • 轨道色使用 var(--xtf-progress-track),激活色使用 var(--xtf-progress-accent),柔和色使用 var(--xtf-progress-soft)
  • 描边宽度使用 var(--xtf-progress-stroke),环形角度使用 var(--xtf-progress-angle) / var(--xtf-progress-dashboard-angle)
  • 环形 dashboard 使用 conic-gradient 实现仪表盘
  • glass 变体轨道为半透明白色 + backdrop-filter 模糊
  • glow / neon 变体使用 box-shadow 发光

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖上述 CSS 变量。

MIT Licensed