鸿蒙实战案例(2)——黑马健康应用首页Tabs的实现

一、预实现图片

二、代码实现

import RecordList from './RecordList'
import SearchHerder from './SearchHeader'
import StatsCard from './StatsCard'
@Component
export default struct RecordIndex{
  build(){
    Column(){
      //1.头部搜素
      SearchHerder()
      //2.统计卡片
      StatsCard()
      //3.记录列表
      RecordList()
        .layoutWeight(1)
    }.width('100%')
    .height('100%')
    .backgroundColor($r('app.color.index_page_background'))
  }
}
import { CommonConstants } from '../../common/constants/CommonConstants'
@Component
export default  struct SearchHerder{
  build(){
    Row({space:CommonConstants.SPACE_6}){
      //搜索栏
      Search({
        placeholder: '搜索饮食或运动信息'
      })
        .textFont({size: 18})
        .layoutWeight(1)
      //信息提示
      Badge({count: 1 ,position:BadgePosition.RightTop , style:{fontSize:12}}){
        Image($r('app.media.ic_public_email'))
          .width(24)
      }

    }
    .width(CommonConstants.THOUSANDTH_940)

  }
}
import BreakpointType from '../../common/bean/BreanpointType'
import BreakpointConstants from '../../common/constants/BreakpointConstants'
import { CommonConstants } from '../../common/constants/CommonConstants'
import DateUtil from '../../common/utils/DateUtil'
import CalorieStats from './CalorieStats'
import DatePickDialog from './DatePickDialog'
import NutrientStats from './NutrientStats'
@Component
export default struct StatsCard {

  @StorageProp('selectedDate') selectedDate: number = DateUtil.beginTimeOfDay(new Date())
  @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointConstants.BREAKPOINT_SM

  controller : CustomDialogController = new CustomDialogController({
    builder: DatePickDialog({selectedDate: new Date(this.selectedDate)})
  })

  build() {
    //从上到下的列式布局
    Column(){
      //1.日期信息
      Row(){
        Text(DateUtil.formatDate(this.selectedDate))
          .fontColor($r('app.color.secondary_color'))
        Image($r('app.media.ic_public_spinner'))
          .width(20)
          .fillColor($r('app.color.secondary_color'))
      }
      .padding(CommonConstants.SPACE_12)
      .onClick(() => this.controller.open())

      //2.统计信息
      Swiper(){
        //2.1 热量统计
        CalorieStats()
        //2.2 营养素统计
        NutrientStats()
      }
      .width('100%')
      .backgroundColor(Color.White)
      .borderRadius(CommonConstants.DEFAULT_18)
      .indicatorStyle({selectedColor:$r('app.color.primary_color')})
      .displayCount(new BreakpointType({
        sm: 1,
        md: 1,
        lg:2
      }).getValue(this.currentBreakpoint))
    }
    .width(CommonConstants.THOUSANDTH_940)
    .backgroundColor($r('app.color.stats_title_bgc'))
    //边框圆弧
    .borderRadius(CommonConstants.DEFAULT_18)
  }
}

运行截图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值