SingleImageCardComponent.ets 2.25 KB
import { Action, CompDTO, ContentDTO, Params } from 'wdBean';
import { CompStyle } from 'wdConstant';
import { Logger } from 'wdKit';
import { WDRouterRule } from 'wdRouter';

const TAG = 'SingleImageCardComponent';
const FULL_PARENT: string = '100%';

/**
 * 单图卡-3行标题/2行标题
 * 枚举值13
 * ImageCard-03
 * 重磅推荐/精选/电视剧/电影/综艺/短剧/更多>/
 */

@Component
export struct SingleImageCardComponent {
  @State compDTO: CompDTO = {} as CompDTO
  @State titleNumber: number = 3 //标题行数

  aboutToAppear() {
    // Logger.debug(TAG + "" + JSON.stringify(this.compDTO.operDataList));
    if(this.compDTO.operDataList[0].newsTitle.length > 26){
      this.titleNumber = 3;
    } else {
      this.titleNumber = 2;
    }
  }

  build() {
    Row() {
      Column() {
        Text(this.compDTO.operDataList[0].newsTitle)
          .fontSize(16)
          .fontWeight(FontWeight.Bold)
          .maxLines(this.titleNumber)//
          .alignSelf(ItemAlign.Start)
          .textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。
          .height(this.titleNumber === 3 ?"80%" : '65%')
        Row() {
          Text('人民日报')
            .height(40)
            .fontSize(14)
            .fontColor(Color.Gray)
          Image($r('app.media.point'))
            .width(16)
            .height(16)
          Text('45分钟前')
            .height(40)
            .fontSize(14)
            .fontColor(Color.Gray)
          Text(this.compDTO.operDataList[0].visitorComment + '评')
            .height(40)
            .fontSize(14)
            .fontColor(Color.Gray)
            .padding({
              left: 10
            })
        }.alignSelf(ItemAlign.Start)
        .height(this.titleNumber === 3 ? "20%" : '35%')
        .justifyContent(FlexAlign.SpaceBetween)
      }
      .alignItems(HorizontalAlign.Start)
      .justifyContent(FlexAlign.SpaceBetween)
      .width('58%')
      Blank(16)
      Image(this.compDTO.operDataList[0].coverUrl)
        .height('78vp')
        .borderRadius(5)
        .aspectRatio(3 / 2)
    }
    .padding(
      { top: 16, bottom: 16, left: 14, right: 14 })
    .width(FULL_PARENT)
    .height(this.titleNumber === 3 ? '127vp' : '106vp')
    .justifyContent(FlexAlign.SpaceBetween)
  }
}