Skip to content

EYearProgress 组件

组件简介

EYearProgress 是一个年度进度展示组件,用于可视化当前年份的流逝进度。它提供了环形进度条和文字说明,适合构建时间管理和年度目标追踪应用。

基本用法

qml
import "components" as Components

Components.ETheme { id: theme }

Components.EYearProgress {
    width: 200
    height: 200
}

属性列表

属性名类型默认值描述
currentDatedatenew Date()当前日期
progressreal0年度进度值(0-1)
showProgressTextbooltrue是否显示进度文本
showYearbooltrue是否显示年份
animatedbooltrue是否启用动画效果
animationDurationint1000动画持续时间(毫秒)
radiusreal80环形进度条半径
strokeWidthreal15环形进度条宽度
backgroundColorcolortheme.borderColor背景环形颜色
progressColorcolortheme.primaryColor进度环形颜色
textColorcolortheme.textColor文本颜色
yearColorcolortheme.textSecondaryColor年份文本颜色

方法列表

方法名参数返回值描述
setDate(date)date设置当前日期
calculateProgress()real计算年度进度值
update()更新组件显示

信号列表

信号名参数描述
progressChanged(progress)real进度值改变时触发
dateChanged(date)date日期改变时触发

扩展示例

自定义样式的年度进度组件

qml
Components.EYearProgress {
    width: 250
    height: 250
    
    radius: 100
    strokeWidth: 20
    backgroundColor: "#e0e0e0"
    progressColor: "#4caf50"
    textColor: "#333333"
    yearColor: "#666666"
    
    showProgressText: true
    showYear: true
    animated: true
    animationDuration: 1500
}

带有时间信息的年度进度组件

qml
Components.EAnimatedWindow {
    width: 300
    height: 350
    title: "年度进度展示"
    visible: true
    
    Column {
        anchors.fill: parent
        padding: 20
        spacing: 20
        
        Components.EYearProgress {
            width: 260
            height: 260
            progressColor: theme.primaryColor
        }
        
        Text {
            id: timeInfo
            text: "当前时间: " + new Date().toLocaleString()
            color: theme.textColor
            anchors.horizontalCenter: parent.horizontalCenter
            font.pointSize: 14
        }
        
        Timer {
            interval: 1000
            running: true
            repeat: true
            onTriggered: {
                timeInfo.text = "当前时间: " + new Date().toLocaleString()
            }
        }
    }
}

多个年度进度对比组件

qml
Components.EAnimatedWindow {
    width: 600
    height: 300
    title: "年度进度对比"
    visible: true
    
    Row {
        anchors.fill: parent
        padding: 20
        spacing: 20
        
        Components.EYearProgress {
            width: 200
            height: 200
            progressColor: "#ff5722"
        }
        
        Column {
            anchors.fill: parent
            spacing: 16
            
            Text {
                text: "年度进度详情"
                font.pointSize: 18
                font.bold: true
                color: theme.textColor
            }
            
            Text {
                id: daysPassed
                text: "已过天数: " + Math.floor(new Date() - new Date(new Date().getFullYear(), 0, 1)) / (1000 * 60 * 60 * 24)
                color: theme.textColor
                font.pointSize: 14
            }
            
            Text {
                id: daysRemaining
                text: "剩余天数: " + (365 - Math.floor(new Date() - new Date(new Date().getFullYear(), 0, 1)) / (1000 * 60 * 60 * 24))
                color: theme.textColor
                font.pointSize: 14
            }
            
            Text {
                id: yearPercentage
                text: "年度进度: " + Math.round((Math.floor(new Date() - new Date(new Date().getFullYear(), 0, 1)) / (1000 * 60 * 60 * 24) / 365) * 100) + "%"
                color: theme.textColor
                font.pointSize: 14
            }
            
            Timer {
                interval: 1000
                running: true
                repeat: true
                onTriggered: {
                    var days = Math.floor(new Date() - new Date(new Date().getFullYear(), 0, 1)) / (1000 * 60 * 60 * 24)
                    daysPassed.text = "已过天数: " + days
                    daysRemaining.text = "剩余天数: " + (365 - days)
                    yearPercentage.text = "年度进度: " + Math.round((days / 365) * 100) + "%"
                }
            }
        }
    }
}

最佳实践

  1. 自动更新:使用 Timer 组件定期更新日期和进度,确保显示的是最新信息
  2. 样式统一:与应用中其他进度组件保持一致的样式和交互方式
  3. 响应式设计:在不同屏幕尺寸下调整组件大小,确保良好的显示效果
  4. 性能优化:避免过于频繁的更新,建议每分钟或每小时更新一次即可
  5. 用户体验:提供清晰的进度文本和年份显示,帮助用户快速理解信息

注意事项

  • 进度值会自动根据当前日期计算,无需手动设置
  • 组件支持闰年计算,会自动调整年度天数
  • 动画效果会使进度变化更平滑,但可能影响性能
  • 可以通过设置 currentDate 属性显示特定日期的年度进度
  • 组件默认显示当前日期的年度进度

使用 VitePress 构建