CardAdvLongImageComponent.ets 2.2 KB
//全标题 "appStyle":"2",
import { CompDTO } from 'wdBean';
import { CommonConstants, CompStyle } from 'wdConstant/Index';
import { ProcessUtils } from 'wdRouter';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import PageModel from '../../viewmodel/PageModel';
import { CardAdvBottom } from './CardAdvBottom';

const TAG: string = 'Card2Component';

/**
 * @Description: 广告---长通栏广告 和 顶部长通栏广告
 * @Author:
 * @Email: liyubing@wondertek.com.cn
 * @CreateDate:
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Component
export struct CardAdvLongImageComponent {
  @State compDTO: CompDTO = {} as CompDTO
  @State haveTitle: boolean = true
  pageModel: PageModel = new PageModel();
  @State loadImg: boolean = false;

  async aboutToAppear(): Promise<void> {
    this.loadImg = await onlyWifiLoadImg();
    this.haveTitle = this.compDTO.matInfo.advSubType === CompStyle.Card_Adv_7;
  }

  aboutToDisappear(): void {

  }

  build() {

    Column() {
      //新闻标题
      if (this.haveTitle) {
        Text(this.compDTO.matInfo.advTitle).width('100%').bottomTextStyle().margin({ bottom: 8, })
      }
      //长图
      Image(this.loadImg ? this.compDTO.matInfo.matImageUrl[0] : '')
        .backgroundColor(this.loadImg ? $r('app.color.color_B0B0B0') : 0xf5f5f5)
        .width(CommonConstants.FULL_WIDTH)
        .aspectRatio(343 / 96)
        .border({
          width: 0.5,
          color: '#0D000000',  // 5% 透明度的黑色
          style: BorderStyle.Solid,
          radius: 4
        })

      CardAdvBottom({ pageModel: this.pageModel, compDTO:this.compDTO }).margin({
        top: 8,
      })
    }
    .width(CommonConstants.FULL_WIDTH)
    .padding({
      left: 10,
      right: 10,
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
    .onClick((event: ClickEvent) => {
      ProcessUtils.openAdvDetail(this.compDTO.matInfo)
    })
  }
}

/*
   标题样式
 */
@Extend(Text)
function bottomTextStyle() {
  .fontSize('18fp')
  .fontColor($r('app.color.color_222222'))
  .maxLines(3)
  .textOverflow({ overflow: TextOverflow.Ellipsis }) // 超出的部分显示省略号。
  .align(Alignment.Start)
  .lineHeight(25)
}