CardSourceInfo.ets 2.85 KB
import { CompDTO, ContentDTO } from 'wdBean'
import { CommonConstants } from 'wdConstant/Index';
import { DateTimeUtils } from 'wdKit/Index';

@Component
export struct CardSourceInfo {
  @State contentDTO: ContentDTO = new ContentDTO();
  @ObjectLink compDTO: CompDTO

  build() {
    Flex() {
      if (this.contentDTO.corner) {
        Text(this.contentDTO.corner)
          .fontSize($r("app.float.font_size_11"))
          .fontColor($r("app.color.color_ED2800"))
          .margin({ right: 2 })
      }
      if (this.contentDTO.rmhPlatform === 1) {
        Text(this.contentDTO.rmhInfo?.rmhName)
          .fontSize($r("app.float.font_size_11"))
          .fontColor($r("app.color.color_B0B0B0"))
          .maxLines(1)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
      } else if (this.contentDTO.source) {
        Text(`${this.contentDTO.source}`)
          .fontSize($r("app.float.font_size_11"))
          .fontColor($r("app.color.color_B0B0B0"))
          .maxLines(1)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
      }
      if (((this.contentDTO.rmhPlatform === 1 && this.contentDTO.rmhInfo?.rmhName && this.contentDTO.rmhInfo?.rmhName != '')  || (this.contentDTO.source && this.contentDTO.source != '')) && (this.getContentDtoBean()?.interactData?.commentNum
        // || DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTime)) != ''
      )) {
        Image($r("app.media.point"))
          .width(11)
          .height(11)
      }
      // 新闻tab下的卡片,2天之前的不显示时间。但是如果是搜索情况下展示的卡片,显示时间
      if (this.contentDTO.isSearch || this.contentDTO.isCollection ||
        !this.contentDTO.isSearch && DateTimeUtils.getCommentTime
        (Number
          .parseFloat(this
            .contentDTO.publishTime))
          .indexOf
          ('-') === -1) {
        Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTime)))
          .fontSize($r("app.float.font_size_11"))
          .fontColor($r("app.color.color_B0B0B0"))
          .flexShrink(0)
      }
      if (this.getContentDtoBean()?.interactData?.commentNum) {
        Text(`${this.getContentDtoBean()?.interactData?.commentNum}评`)
          .fontSize($r("app.float.font_size_11"))
          .fontColor($r("app.color.color_B0B0B0"))
          .flexShrink(0)
          .margin({ left: 6 })
          .visibility(Number(this.getContentDtoBean()?.interactData?.commentNum) === 0 ? Visibility.None : Visibility.Visible)
      }
    }
    .width(CommonConstants.FULL_WIDTH)
    .margin({ top: 8 })
  }

  /**
   *  获取稿件业务对象
   * @returns
   */
  private getContentDtoBean(): ContentDTO {
    if (this.compDTO == undefined) {
      return this.contentDTO
    }
    if(this.compDTO.operDataList.length == 0){
      return this.contentDTO
    }
    return this.compDTO.operDataList[0]
  }
}