ZhGridLayout03.ets 2.59 KB
import { Action, CompDTO, ContentDTO, Params } from 'wdBean';
import { CompStyle } from 'wdConstant';
import { Logger } from 'wdKit';
import { WDRouterRule } from 'wdRouter';
import { ProcessUtils } from 'wdRouter';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { InfomationCardClick } from '../../utils/infomationCardClick'

const TAG = 'Zh_Grid_Layout-03';
const FULL_PARENT: string = '100%';
let listSize: number = 4;

/**
 * 金刚卡位
 * 枚举值Zh_Grid_Layout-03
 * Zh_Grid_Layout-03
 *
 */
@Preview
@Component
export struct ZhGridLayout03 {
  @State pageId: string = '';
  @State pageName: string = '';
  @State compDTO: CompDTO = {} as CompDTO
  @State loadImg: boolean = false;

  async aboutToAppear(): Promise<void> {
    if (this.compDTO.operDataList) {
      listSize = this.compDTO.operDataList.length > 5 ? 4 : this.compDTO.operDataList.length;
    }
    this.loadImg = await onlyWifiLoadImg();
  }

  build() {
    GridRow({
      columns: { sm: listSize, md: 8 },
      breakpoints: { value: ['320vp', '520vp', '840vp'] }
    }) {
      ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
        GridCol() {
          this.buildItemCard(this.compDTO.operDataList[index]);
        }
      })
    }
    .padding({
      left: 10,
      right: 10,
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
    .backgroundColor(0xffffff)
    .width('100%')
  }

  /**
   * 组件项
   *
   * @param programmeBean item 组件项, 上面icon,下面标题
   */
  @Builder
  buildItemCard(item: ContentDTO) {
    Column() {
      Image(this.loadImg ? item.coverUrl : '')
        .backgroundColor(0xf5f5f5)
        .width(44)
        .aspectRatio(1 / 1)
        // .margin({
        //   bottom: 16
        // })
      Text(item.newsTitle)
        .fontSize(13)
        .maxLines(1)
        .margin({
          top: 8,
          bottom:11
        })
        .textOverflow({ overflow: TextOverflow.Ellipsis })

    }
    .width('100%')
    .onClick((event: ClickEvent) => {
      console.log('333rt',JSON.stringify(item))
      InfomationCardClick.track(this.compDTO, item, this.pageId, this.pageName)

      ProcessUtils.processPage(item)
      // if (item.objectType === '11') {
      //   ProcessUtils.jumpExternalWebPage
      //   ProcessUtils.jumpChannelTab(item.objectId, item.pageId, item.newsTitle)
      // } else  if(item.objectType === '6'){
      //   ProcessUtils.jumpExternalWebPage(item.linkUrl)
      //   //ProcessUtils.gotoWeb(item);
      // }else{
      //   ProcessUtils.processPage(item)
      // }
    })
  }
}