SearchContentComponent.ets 2.43 KB
import { CompDTO, ContentDTO, FullColumnImgUrlDTO } from 'wdBean';
import { CommonConstants } from 'wdConstant/Index';
import { ProcessUtils } from 'wdRouter';
import { CardSourceInfo } from '../cardCommon/CardSourceInfo'
import { CardMediaInfo } from '../cardCommon/CardMediaInfo'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
const TAG: string = 'Card4Component';

/**
 * 上图下文,用于搜索页命中搜索内容展示
 */
@Component
export struct SearchContentComponent {
  @State contentDTO: ContentDTO = new ContentDTO();
  @State loadImg: boolean = false;
  @State clicked: boolean = false;
  @State str01: string = '';
  @State str02: string = '';
  @State str03: string = '';


  async aboutToAppear(): Promise<void> {
    this.loadImg = await onlyWifiLoadImg();
    this.titleInit();
  }

  titleInit() {
    this.str01 = this.contentDTO.contentText?.split('<em>')[0] || '';
    this.str02 = this.contentDTO.contentText?.split('<em>')[1].split('</em>')[0] || '';
    this.str03 = this.contentDTO.contentText?.split('<em>')[1].split('</em>')[1] || '';
  }

  build() {
    Column() {
      //body
      Column() {
        //新闻标题
        Text(this.contentDTO.newsTitle)
          .fontSize($r('app.float.font_size_17'))
          .fontColor(this.clicked ? 0x848484 : $r('app.color.color_222222'))
          .maxLines(3)
          .textOverflow({ overflow: TextOverflow.Ellipsis }) // 超出的部分显示省略号。

        // 命中内容
        Text(this.contentDTO.contentText) {
          Span(this.str01)
          Span(this.str02)
            .fontColor(0xED2800)
          Span(this.str03)
        }
        .fontSize(13)
        .width(CommonConstants.FULL_PARENT)
        .margin({ top: 8 })
        .fontColor(0x222222)
      }
      .width('100%')
      .justifyContent(FlexAlign.Start)
      .alignItems(HorizontalAlign.Start)
      .onClick((event: ClickEvent) => {
        this.clicked = true;
        ProcessUtils.processPage(this.contentDTO)
      })
      //bottom 评论等信息
      CardSourceInfo({compDTO:new CompDTO, contentDTO: this.contentDTO })
    }
    .width(CommonConstants.FULL_WIDTH)
    .padding({
      left: $r('app.float.card_comp_pagePadding_lf'),
      right: $r('app.float.card_comp_pagePadding_lf'),
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
  }
}


@Extend(Text)
function bottomTextStyle() {
  .fontSize(12)
  .fontColor('#B0B0B0')
}