Skip to content

EFitnessProgress 组件

组件简介

EFitnessProgress 是一个健身进度展示组件,用于可视化健身目标的完成情况。它提供了环形进度条和文字说明,适合构建健身追踪和目标管理应用。

基本用法

qml
import "components" as Components

Components.ETheme { id: theme }

Components.EFitnessProgress {
    width: 200
    height: 200
    progress: 0.75
    target: 10000
    current: 7500
    unit: "步"
    title: "今日步数"
}

属性列表

属性名类型默认值描述
progressreal0进度值(0-1)
targetint100目标值
currentint0当前值
unitstring""数值单位
titlestring""组件标题
showProgressTextbooltrue是否显示进度文本
showUnitbooltrue是否显示单位
animatedbooltrue是否启用动画效果
animationDurationint1000动画持续时间(毫秒)
radiusreal80环形进度条半径
strokeWidthreal15环形进度条宽度
backgroundColorcolortheme.borderColor背景环形颜色
progressColorcolortheme.primaryColor进度环形颜色
textColorcolortheme.textColor文本颜色
unitColorcolortheme.textSecondaryColor单位文本颜色
titleColorcolortheme.textColor标题文本颜色

方法列表

方法名参数返回值描述
setProgress(progress)real设置进度值
setTarget(target)int设置目标值
setCurrent(current)int设置当前值
update()更新组件显示

信号列表

信号名参数描述
progressChanged(progress)real进度值改变时触发
targetChanged(target)int目标值改变时触发
currentChanged(current)int当前值改变时触发

扩展示例

多个健身进度组件

qml
Components.EAnimatedWindow {
    width: 450
    height: 300
    title: "健身进度展示"
    visible: true
    
    Row {
        anchors.fill: parent
        padding: 20
        spacing: 20
        
        Components.EFitnessProgress {
            width: 150
            height: 150
            progress: 0.75
            target: 10000
            current: 7500
            unit: "步"
            title: "今日步数"
            progressColor: "#4caf50"
        }
        
        Components.EFitnessProgress {
            width: 150
            height: 150
            progress: 0.6
            target: 30
            current: 18
            unit: "分钟"
            title: "运动时长"
            progressColor: "#2196f3"
        }
        
        Components.EFitnessProgress {
            width: 150
            height: 150
            progress: 0.85
            target: 2000
            current: 1700
            unit: "卡路里"
            title: "消耗热量"
            progressColor: "#ff5722"
        }
    }
}

自定义样式的健身进度组件

qml
Components.EFitnessProgress {
    width: 250
    height: 250
    progress: 0.9
    target: 5
    current: 4.5
    unit: "公里"
    title: "今日跑步"
    
    radius: 100
    strokeWidth: 20
    backgroundColor: "#e0e0e0"
    progressColor: "#9c27b0"
    textColor: "#333333"
    unitColor: "#666666"
    titleColor: "#333333"
    
    showProgressText: true
    showUnit: true
    animated: true
    animationDuration: 1500
}

动态更新的健身进度组件

qml
Components.EAnimatedWindow {
    width: 250
    height: 300
    title: "动态进度展示"
    visible: true
    
    Column {
        anchors.fill: parent
        padding: 20
        spacing: 20
        
        Components.EFitnessProgress {
            id: fitnessProgress
            width: 210
            height: 210
            progress: 0.5
            target: 100
            current: 50
            unit: "%"
            title: "完成度"
        }
        
        Row {
            spacing: 10
            anchors.horizontalCenter: parent.horizontalCenter
            
            Components.EButton {
                text: "减少"
                onClicked: {
                    fitnessProgress.current = Math.max(0, fitnessProgress.current - 10)
                    fitnessProgress.progress = fitnessProgress.current / fitnessProgress.target
                }
            }
            
            Components.EButton {
                text: "增加"
                onClicked: {
                    fitnessProgress.current = Math.min(fitnessProgress.target, fitnessProgress.current + 10)
                    fitnessProgress.progress = fitnessProgress.current / fitnessProgress.target
                }
            }
        }
    }
}

最佳实践

  1. 进度值设置:确保 progress 值在 0-1 范围内
  2. 目标和当前值:合理设置目标值和当前值,使进度展示有意义
  3. 单位选择:根据实际需求选择合适的单位,如步数、分钟、卡路里等
  4. 颜色搭配:使用与应用主题一致的颜色,或根据不同类型的健身数据使用不同颜色
  5. 响应式设计:在不同屏幕尺寸下调整组件大小,确保良好的显示效果

注意事项

  • 进度值会自动限制在 0-1 范围内
  • 当前值超过目标值时,进度条会显示为满
  • 动画效果会使进度变化更平滑,但可能影响性能
  • 组件支持触摸操作,但默认不提供交互功能
  • 可以通过自定义样式改变组件的外观和尺寸

使用 VitePress 构建