PlayerTitleComponent.ets 2.6 KB
import lottie from '@ohos/lottie'
import { ContentDetailDTO, LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index'
import { LiveFollowComponent, LottieView } from 'wdComponent/Index'
import { NumberFormatterUtils } from 'wdKit/Index'

/**
 *  沉浸式直播--- 头部标题
 */
@Preview
@Component
export struct PlayerTitleComponent {
  @Consume liveRoomDataBean: LiveRoomDataBean
  @Consume liveState: string
  @Consume contentDetailData: ContentDetailDTO
  aboutToDisappear(): void {
    if (this.contentDetailData.liveInfo?.liveState == 'running') {
      lottie.destroy('live_status_wait')
    }
  }

  build() {
    Column() {
      Row() {
        Text(this.contentDetailData.newsTitle || '')
          .maxLines(2)
          .fontSize(16)
          .fontWeight(500)
          .fontColor(Color.White)
      }.margin({ bottom: 10 })

      Row() {
        this.getLiveStatusView()
      }

    }
    .width('100%')
    .alignItems(HorizontalAlign.Start)
    .padding({
      top: 12,
      left: 16
    })

  }

  @Builder
  getLiveStatusView() {
    if (this.contentDetailData.rmhInfo?.rmhName) {
      LiveFollowComponent({
        rmhInfo: this.contentDetailData.rmhInfo
      }).margin({
        right: 10
      })

    }

    if (this.liveRoomDataBean.liveId) {
      Row() {
        if (this.liveState == 'running') {
          Stack() {
            Image($r('app.media.icon_live_status_running_back'))
              .width(22)
              .height(18)
            LottieView({
              name: 'live_status_wait',
              path: "lottie/live_detail_living.json",
              lottieWidth: 9,
              lottieHeight: 9,
              autoplay: true,
              loop: true,
            })
              .margin({ right: 2 })
          }.margin({ right: 1 })

          // Image($r('app.media.icon_live_status_running'))
          //   .width(22)
          //   .height(18)
          //   .margin({ right: 1 })
        }

        Text(this.liveState == 'running' ? '直播中' : '回看')
          .fontSize(11)
          .fontWeight(400)
          .fontColor(Color.White)
        if (this.liveRoomDataBean.pv > 0) {
          Image($r('app.media.icon_live_player_status_end'))
            .width(12)
            .height(12)
          Text(`${NumberFormatterUtils.formatNumberWithWan(this.liveRoomDataBean.pv)}人参与`)
            .fontSize('11fp')
            .fontWeight(400)
            .fontColor(Color.White)
        }

      }
      .backgroundColor('#4D000000')
      .borderRadius(2)
      .padding(this.liveState == 'running' ? {
        left: 0,
        right: 4,
        top: 0,
        bottom: 0
      } : 4)
    }
  }
}