ZhGridLayout02NewsContent.ets 2.2 KB
import { CompDTO, ContentDTO, LiveRoomDataBean } from 'wdBean';
import { CommonConstants } from 'wdConstant/Index';
import { Logger } from 'wdKit/Index';
import { ProcessUtils } from 'wdRouter';
import PageViewModel from '../../viewmodel/PageViewModel';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';

let listSize: number = 2;

/**
 * 双图卡 的标题组件
 *
 */
@Component
export struct ZhGridLayout02NewsContent {
  @ObjectLink compDTO: CompDTO
  @State loadImg: boolean = false;

  async aboutToAppear(): Promise<void> {

    this.loadImg = await onlyWifiLoadImg();
  }

  build() {

    if (this.compDTO != undefined) {
      GridRow({
        gutter: { x: 12, y: 13 },
        columns: { sm: listSize, md: 2 },
        breakpoints: { value: ['320vp', '520vp', '840vp'] }
      }) {
        ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
          GridCol() {
            this.buildItemCard(item);
          }
        })
      }.width("100%").padding({ left: 16, right: 16 })
    }

  }

  @Builder
  buildItemCard(item: ContentDTO) {
    Column() {
      Stack({ alignContent: Alignment.BottomEnd }) {
        Image(this.loadImg ? item.fullColumnImgUrls[0].url : '')
          .backgroundColor(0xf5f5f5)
          .width('100%')
          .height(95)
          .borderRadius(4)
        if (item.liveRoomDataBean != null && item.liveRoomDataBean.pv > 0) {
          Text(this.computeShowNum(item.liveRoomDataBean.pv))
            .fontSize('11vp')
            .fontWeight(400)
            .fontColor(Color.White)
            .margin({
              right: '5vp',
              bottom: '5vp'
            })
        }
      }

      Text(item.newsTitle)
        .margin({ top: '6',bottom:'10' })
        .fontSize(13)
        .maxLines(2)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
    }
    .width('100%')
    .onClick(() => {
      ProcessUtils.processPage(item)
    })
  }

  private computeShowNum(count: number): string {
    if (count >= 10000) {
      let num = (count / 10000).toFixed(1)
      if (Number(num.substring(num.length - 1)) == 0) {
        num = num.substring(0, num.length - 2)
      }
      return num + '万人参加'
    }
    return `${count}人参加`
  }
}