harmonyOS next任务进度功能(新增任务选中统计)

class Task{
  //id
  static  id:number =1
  //任务名称
  name:string =`任务${Task.id++}`
  //任务状态:是否完成
  finished: boolean = false
}
@Styles function card(){
  .width('95%')
  .padding(20)
  .backgroundColor(Color.White)
  .borderRadius(15)
  //为组件添加阴影效果。
  .shadow({radius:6,color:'#1F000000',offsetX: 2,offsetY: 4})
}
//任务进度
@Entry
@Component
struct Page2 {
  //跟新当前状态 //跟新已完成的任务数
  changetext(){
  //跟新当前状态
    // 更新任务总量
    this.totalTask =this.tasks.length
  //跟新已完成的任务数
  this.finishTask =this.tasks.filter(item => item.finished).length

}
  //总任务数
  @State totalTask: number =0
  //已完成的任务数
  @State finishTask: number =0
  //任务数组
  @State tasks: Task[] = []
  build() {
  Column(){
//r任务进度卡片
    Row(){
      Text('任务进度').fontSize(30).fontWeight(FontWeight.Bold)
      Row(){

        Stack(){
          //环行进度条***********
          Progress({
            value:this.finishTask,
            total:this.totalTask,
            type:ProgressType.Ring
          }).width(100)
          Row(){
            Text(this.finishTask.toString()).fontSize(24).fontColor('#36D')
            Text('/'+this.totalTask.toString()).fontSize(24)
          }

        }

      }

    }
    .card()
    .margin({top:20,bottom:10})
    .justifyContent(FlexAlign.SpaceEvenly)
    Button('新增任务').width(200)
      //点击新增任务数据
      .onClick(() =>{
        this.tasks.push(new Task())
       // 更新任务总量
       //  this.totalTask =this.tasks.length
        this.changetext()
      })
List({space:10}){

        ForEach(
          this.tasks,
          (item:Task,index:number) =>{
            ListItem(){
            Row()
            {
              Text(item.name).fontSize(20)
              Checkbox().select(item.finished)
                .onChange( val =>{
                  //跟新当前状态
                  item.finished =val
                  //跟新已完成的任务数
                  this.changetext()
                  // this.finishTask =this.tasks.filter(item => item.finished).length
                })
            }.card().justifyContent(FlexAlign.SpaceBetween)
          }

          }
        )

}
.width('100%')
    .layoutWeight(1)


    }
    .height('100%')
    .width('100%')
    .backgroundColor('#F1F2F3')
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值