SearchContentComponent.ets 3.02 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';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import { SearchShowRed, titleInitRes, textItem } from '../../utils/searchShowRed';
import router from '@ohos.router'
import { persistentStorage, hasClicked } from '../../utils/persistentStorage';

const TAG: string = 'Card4Component';

/**
 * 上图下文,用于搜索页命中搜索内容展示
 */
@Component
export struct SearchContentComponent {
  @ObjectLink compDTO: CompDTO
  @State pageId: string = '';
  @State pageName: string = '';
  @State contentDTO: ContentDTO = new ContentDTO();
  @State loadImg: boolean = false;
  @State clicked: boolean = false;
  @State textArr: textItem[] = []


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

    const curRouter = router.getState().name;
    this.clicked = hasClicked(this.contentDTO.objectId, curRouter)
  }

  titleInit() {
    const titleInitRes:titleInitRes = SearchShowRed.titleInit(this.contentDTO.contentText || '');
    // this.titleMarked = titleInitRes.titleMarked;
    this.textArr = titleInitRes.textArr;
  }

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

        // 命中内容
        Text() {
          ForEach(this.textArr, (textItem: textItem) => {
            if (textItem.isRed) {
              Span(textItem.content)
                .fontColor(0xED2800)
            } else {
              Span(textItem.content)
            }
          })
        }
        .fontSize(13)
        .width(CommonConstants.FULL_PARENT)
        .margin({ top: 8 })
        .fontColor(0x222222)
      }
      .width('100%')
      .justifyContent(FlexAlign.Start)
      .alignItems(HorizontalAlign.Start)
      .onClick((event: ClickEvent) => {
        InfomationCardClick.track(this.compDTO, this.contentDTO, this.pageId, this.pageName)
        if (router.getState().name !== 'MyCollectionListPage') {
          this.clicked = true;
        }
        ProcessUtils.processPage(this.contentDTO)
      })
      //bottom 评论等信息
      CardSourceInfo({compDTO:new CompDTO, contentDTO: this.contentDTO })
    }
    .padding({
      left: 10,
      right: 10,
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
    .backgroundColor(0xffffff)
    .width(CommonConstants.FULL_WIDTH)
  }
}


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