DetailPlayLiveCommon.ets 5.08 KB
import { Action, ContentDetailDTO } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import router from '@ohos.router';

import { DetailPlayLivePage } from './DetailPlayLivePage';
import { DetailPlayVLivePage } from './DetailPlayVLivePage';
import { Logger } from 'wdKit/Index';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';

const TAG = 'DetailPlayLiveCommon'

/**
 * @Description: 沉浸式和非沉浸式直播页面
 * @Author:
 * @Email:
 * @CreateDate:
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Entry
@Component
export struct DetailPlayLiveCommon {
  private liveViewModel: LiveViewModel = new LiveViewModel()
  @Provide relId: string = ''
  @Provide contentId: string = ''
  @Provide relType: string = ''
  @Provide liveState: string = ''
  @Provide liveStyle: number = -1
  @Provide playUrl: string = ''
  @Provide imgUrl: string = ''
  @Provide pageShow: number = -1
  @Provide pageHide: number = -1
  @Provide pageBackPress: number = -1
  @Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
  @Provide publishCommentModel: publishCommentModel = new publishCommentModel()
  // 横屏或竖屏  general-竖屏,news-横屏
  @State liveLandscape: string = ''

  async aboutToAppear(): Promise<void> {
    const par: Action = router.getParams() as Action;
    const params = par?.params;
    this.relId = params?.extra?.relId || '';
    this.relType = params?.extra?.relType || '';
    this.contentId = params?.contentID || '';
    this.getContentDetail()

  }

  build() {
    Column() {
      // 直播预约或横屏直播统一进横屏直播
      if (this.liveState === 'wait' || this.liveLandscape === 'news') {
        // 非沉浸式直播
        DetailPlayLivePage({ contentId: this.contentId, relId: this.relId, relType: this.relType })
      } else if (this.liveLandscape === 'general') {
        // 沉浸式直播
        DetailPlayVLivePage()
      }
    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Black)
    .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  }

  /**
   * 查询视频详情用于评论展示
   */
  getContentDetail() {
    this.liveViewModel.getContentDetail(this.contentId, this.relId, this.relType)
      .then((data: Array<ContentDetailDTO>) => {
        console.log(TAG, '查询视频详情用于评论展示 getContentDetail:', JSON.stringify(data))
        if (data) {
          let detailData = data[0]
          this.liveLandscape =
            detailData?.liveInfo?.liveLandScape //String(this.contentDetailData?.liveInfo?.liveLandScape || '')

          this.liveState = detailData.liveInfo?.liveState


          if (this.liveState === 'wait' || this.liveLandscape === 'news') {
            this.contentDetailData = data[0]
          } else if (this.liveLandscape === 'general') {
            //todo  不加setTimeOut ,接口返回的数据 就没法让PlayerComponent #@Consume @Watch('updateData') liveDetailsBean 的updateData方法运行
            setTimeout(() => {
              this.contentDetailData = data[0]
            }, 10)
          }

          console.log(TAG, '查询视频详情用于评论展示 openComment:', detailData.openComment)
          this.publishCommentModel.targetId = String(detailData?.newsId || '')
          this.publishCommentModel.targetRelId = String(detailData?.reLInfo?.relId || '')
          this.publishCommentModel.targetTitle = detailData?.newsTitle
          this.publishCommentModel.targetRelType = String(detailData?.reLInfo?.relType || '')
          this.publishCommentModel.targetRelObjectId = String(detailData?.reLInfo?.relObjectId || '')
          this.publishCommentModel.keyArticle = String(detailData?.keyArticle || '')
          this.publishCommentModel.targetType = String(detailData?.newsType || '')
          this.publishCommentModel.visitorComment = String(detailData?.visitorComment || '')
          this.publishCommentModel.commentContent = ''
          this.liveStyle = detailData.liveInfo?.liveStyle

          if (detailData.fullColumnImgUrls && detailData.fullColumnImgUrls.length > 0) {
            this.imgUrl = detailData.fullColumnImgUrls[0].url
          }

          if (detailData.liveInfo.liveState == 'end') {
            this.playUrl = detailData.liveInfo.vlive[0].replayUri
          }
          //console.error('XXXXZZZZ', "liveLandscape =" + this.liveLandscape + '  this.liveState =' + this.liveState)
        }
      })
  }

  // /**
  //  *
  //  * @returns true : 沉浸式;false : 非沉浸式
  //  */
  // isImmersionLive(): boolean {
  //
  //   let flag = false
  //
  //   if (this.liveState === 'wait' || this.liveLandscape === 'news') {
  //     flag = false
  //   } else if (this.liveLandscape === 'general') {
  //     flag = true
  //   }
  //
  //   return flag
  // }

  onPageShow() {
    this.pageShow = Math.random()
    Logger.info(TAG, 'onPageShow')
  }

  onPageHide() {
    this.pageHide = Math.random()
    Logger.info(TAG, 'onPageHide')
  }

  onBackPress(): boolean | void {
    this.pageBackPress = Math.random()
    Logger.info(TAG, 'onBackPress')
    return true
  }
}