ZhSingleColumn04.ets 3.06 KB
import { CompDTO, ContentDTO } from 'wdBean';
import { CommonConstants } from 'wdConstant';
import { ProcessUtils } from 'wdRouter';
import { InfomationCardClick } from '../../utils/infomationCardClick'

const TAG = 'Zh_Single_Column-04';

/**
 * 人民号主题卡
 * 枚举值 Zh_Single_Column-04
 */
@Component
export struct ZhSingleColumn04 {
  @State pageId: string = '';
  @State pageName: string = '';
  @State compDTO: CompDTO = {} as CompDTO
  operDataList: ContentDTO[] = [
  // {newsTitle: "民检普法课堂:正当防卫是什么正当防卫是什么正当防卫是什么正当防卫是什么?", tagWord: 1} as ContentDTO,
  // {newsTitle: "审批站”进菜市场 学才艺有云课堂", tagWord: 2} as ContentDTO,
  ]

  aboutToAppear() {
    this.operDataList = this.compDTO.operDataList;
  }

  build() {
    Column() {
      Row() {
        Image($r("app.media.redLine"))
          .width(3)
          .height(16)
          .margin({ right: 4 })
        Text(this.compDTO.objectTitle)
          .fontSize($r("app.float.font_size_17"))
          .fontColor($r("app.color.color_222222"))
          .fontWeight(600)
      }
      .width(CommonConstants.FULL_WIDTH)
      .margin({ bottom: 10 })

      Column() {
        ForEach(this.operDataList, (item: ContentDTO) => {
          this.rmhThemeItem(item)
        })
      }
    }
    .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%')
  }

  @Builder
  rmhThemeItem(item: ContentDTO) {
    Row() {
      Image($r('app.media.rmh_theme_book_icon'))
        .width(12)
        .margin({ left: 12, right: 8 })
      Text(item.newsTitle)
        .fontSizeColorWeight($r('app.float.font_size_18'), $r('app.color.color_222222'), 400)
        .maxLines(1)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .layoutWeight(1)
      if (item.tagWord === 1) {
        Text('热')
          .padding(3)
          .borderRadius(4)
          .fontSizeColorWeight($r('app.float.vp_12'), '#F07E46', 500)
          .backgroundColor('rgba(240, 126, 70, 0.2)')
          .margin({ right: 21 })
      } else if (item.tagWord === 2) {
        Text('新')
          .padding(3)
          .borderRadius(4)
          .fontSizeColorWeight($r('app.float.vp_12'), '#468DF0', 500)
          .backgroundColor('rgba(70, 141, 240, 0.2)')
          .margin({ right: 21 })
      }
    }
    .width(CommonConstants.FULL_WIDTH)
    .height(32)
    .margin({ bottom: 8 })
    .backgroundImage($r('app.media.rmh_theme_bg'))
    .backgroundImageSize({ width: CommonConstants.FULL_WIDTH, height: CommonConstants.FULL_WIDTH })
    .onClick(() => {
      InfomationCardClick.track(this.compDTO, item, this.pageId, this.pageName)
      ProcessUtils.processPage(item)
    })
  }
}

@Extend(Text)
function fontSizeColorWeight(fontSize: Resource, fontColor: Resource | string,
                             fontWeight:
                               number) {
  .fontSize(fontSize)
  .fontColor(fontColor)
  .fontWeight(fontWeight)
}