DetailPlayLiveCommon.ets 4.52 KB
import { Action, ContentDetailDTO, LiveDetailsBean } 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'

@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 liveDetailsBean: LiveDetailsBean = {} as LiveDetailsBean
  @Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
  @Provide publishCommentModel: publishCommentModel = new publishCommentModel()

  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 || '';
    await this.getContentDetail()
    this.getLiveDetails()
  }

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

  /**
   * 查询视频详情用于评论展示
   */
  async getContentDetail() {
    await this.liveViewModel.getContentDetail(this.contentId, this.relId, this.relType)
      .then((data: Array<ContentDetailDTO>) => {
        console.log(TAG, '查询视频详情用于评论展示 getContentDetail:', JSON.stringify(data))
        if (data) {
          this.contentDetailData = data[0];
          // if (this.contentDetailData.openComment === 1) {
          console.log(TAG, '查询视频详情用于评论展示 openComment:', this.contentDetailData.openComment)
          this.publishCommentModel.targetId = String(this.contentDetailData?.newsId || '')
          this.publishCommentModel.targetRelId = String(this.contentDetailData?.reLInfo?.relId || '')
          this.publishCommentModel.targetTitle = this.contentDetailData?.newsTitle
          this.publishCommentModel.targetRelType = String(this.contentDetailData?.reLInfo?.relType || '')
          this.publishCommentModel.targetRelObjectId = String(this.contentDetailData?.reLInfo?.relObjectId || '')
          this.publishCommentModel.keyArticle = String(this.contentDetailData?.keyArticle || '')
          this.publishCommentModel.targetType = String(this.contentDetailData?.newsType || '')
          this.publishCommentModel.visitorComment = String(this.contentDetailData?.visitorComment || '')
          this.publishCommentModel.commentContent = ''
          // }
        }
      })
  }

  /**
   * 获取直播信息,可区分横竖屏直播
   */
  getLiveDetails() {
    this.liveViewModel.getLiveDetails(this.contentId, this.relId, this.relType)
      .then(
        (data) => {
          if (data.length > 0) {
            this.liveDetailsBean = data[0]
            this.liveState = this.liveDetailsBean.liveInfo?.liveState
            this.liveStyle = this.liveDetailsBean.liveInfo.liveStyle

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

            if (this.liveDetailsBean.liveInfo.liveState == 'end') {
              this.playUrl = this.liveDetailsBean.liveInfo.vlive[0].replayUri
            }

            console.log(TAG, 'getLiveDetails:', JSON.stringify((this.liveDetailsBean)))
          }
        },
        () => {

        })
  }

  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
  }
}