HeadPictureCardComponent.ets 1.62 KB
import { CommonConstants } from 'wdConstant';
import thermal from '@ohos.thermal';
import { CompDTO } from '../../repository/bean/CompDTO';
import { ContentDTO } from '../../repository/bean/ContentDTO';
import { CompUtils } from '../../utils/CompUtils';

@Component
export struct HeadPictureCardComponent {
  @State compDTO: CompDTO = {} as CompDTO

  build() {
    Stack() {
      Image(this.compDTO.operDataList[0].coverUrl)
        .width(CommonConstants.FULL_WIDTH)
        .height(CommonConstants.FULL_HEIGHT)

      if (this.compDTO.operDataList[0].newsTitle != null) {
        Row()
          .width(CommonConstants.FULL_WIDTH)
          .height(59)
          .linearGradient({
            colors:[
              ['rgba(0, 0, 0, 0.0)', 0.0], ['rgba(0, 0, 0, 0.3)', 1.0]
            ]
          })
        Row() {
          Text(this.compDTO.operDataList[0].newsTitle)
            .width(CommonConstants.FULL_WIDTH)
            .height(CommonConstants.FULL_HEIGHT)
            .fontColor(Color.White)
            .fontSize($r('app.float.normal_text_size'))
            .fontWeight(FontWeight.Bold)
            .maxLines(2)
            .align(Alignment.Bottom)
        }
        .height(40)
        .margin({left: 12, bottom: 10, right: 12})
      }
    }
    .alignContent(Alignment.Bottom)
    .width(CommonConstants.FULL_WIDTH)
    .aspectRatio(imageSizeRatio(this.compDTO.operDataList[0].coverSize))
    .height(200)
  }
}

function imageSizeRatio(size: string): number {
  if (size != null) {
    let parts: string[] = size.split("*");
    let f = Number(parts[0])
    let s = Number(parts[1])
    return f / s;
  } else {
    return 1.0
  }
}