SingleRow03Component.ets 2.81 KB
import { ContentDTO } from 'wdBean';


const TAG = 'SingleRow03Component';

/**
 * 直播横划卡
 * Single_Row-03
 * 支持添加直播内容
 */
@Component
export struct SingleRow03Component {
  @State dataList?: ContentDTO[] = undefined

  build() {
    List( {space: 2.5}){
      ForEach(this.dataList, (item : ContentDTO, index?: number) =>{
        ListItem(){
           this.contentItem(item)
        }

      } , (item: ContentDTO) => JSON.stringify(item))

    }
    .listDirection(Axis.Horizontal)
    .lanes(1)
    .scrollBar(BarState.Off)
  }

  @Builder
  contentItem(item: ContentDTO){
    Column(){
      RelativeContainer() {
        Image(item.coverUrl)
          .width('100%')
          .height($r('app.float.single_row_03_img_height'))
          .borderRadius($r("app.float.image_border_radius"))
          .objectFit(ImageFit.Cover)
          .alignRules({
            top: { anchor: '__container__', align: VerticalAlign.Top },
            left: { anchor: '__container__', align: HorizontalAlign.Start }
          })
          .id('img_cover')

        Text(item.title)
          .width('100%')
          .margin({ top: 4, left: 6, right: 6 })
          .fontWeight(FontWeight.Normal)
          .textAlign(TextAlign.Start)
          .fontSize($r('app.float.font_size_14'))
          .fontColor($r('app.color.color_333333'))
          .maxLines(2)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
          .alignRules({
            top: {anchor:'img_cover', align: VerticalAlign.Bottom},
            left: {anchor: 'img_cover', align: HorizontalAlign.Start},
            right:{anchor: 'img_cover', align: HorizontalAlign.End}
          })
          .id("tv_title")

        Button('预约')
          .width(58)
          .height(24)
          .margin({bottom: 6})
          .backgroundColor(0xF55A42)
          .id('button')
          .alignRules({
            bottom: {anchor:'__container__', align: VerticalAlign.Bottom},
            right:{anchor: '__container__', align: HorizontalAlign.End}
          })
          .onClick((event: ClickEvent) => {

        })

        Text(item.startTime)
          .fontWeight(FontWeight.Normal)
          .textAlign(TextAlign.Start)
          .margin({ left: 6})
          .fontSize($r('app.float.font_size_10'))
          .fontColor($r('app.color.color_999999'))
          .maxLines(1)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
          .alignRules({
            center: {anchor:'button', align:VerticalAlign.Center},
            left: {anchor: 'tv_title', align: HorizontalAlign.Start},
          })
          .id("tv_start_time")



      }
      .width('100%')
      .height('100%')
    }
    .width($r('app.float.single_row_03_item_width'))
    .height($r('app.float.single_row_03_item_height'))
    .backgroundColor(Color.White)
    .alignItems(HorizontalAlign.Start)


  }
}