DetailPlayLivePage.ets 6.33 KB
import { ContentDetailDTO, LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import { TabComponent } from '../widgets/details/TabComponent';
import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
import { DisplayDirection } from 'wdConstant/Index';
import mediaquery from '@ohos.mediaquery';
import { Logger, WindowModel } from 'wdKit/Index';
import { router, window } from '@kit.ArkUI';
import { devicePLSensorManager } from 'wdDetailPlayApi/Index';
import { LiveCommentComponent } from 'wdComponent/Index';
import { WDPlayerController } from 'wdPlayer/Index';
import { OperRowListView } from 'wdComponent/src/main/ets/components/view/OperRowListView';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';
import { ResponseDTO } from 'wdNetwork/Index';

let TAG: string = 'DetailPlayLivePage';

@Component
export struct DetailPlayLivePage {
  //横竖屏,默认竖屏
  @Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL
  playerController: WDPlayerController = new WDPlayerController();
  liveViewModel: LiveViewModel = new LiveViewModel()
  @State relId: string = ''
  @State contentId: string = ''
  @State relType: string = ''
  @Provide liveDetailsBean: LiveDetailsBean = {} as LiveDetailsBean
  @Provide liveRoomDataBean: LiveRoomDataBean = {} as LiveRoomDataBean
  @State tabs: string[] = []
  //监听屏幕横竖屏变化
  listener = mediaquery.matchMediaSync('(orientation: landscape)');
  @Consume @Watch('onPageShowCus') pageShow: number
  @Consume @Watch('onPageHideCus') pageHide: number
  @Consume @Watch('onBackPressCus') pageBackPress: number
  @State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
  @State publishCommentModel: publishCommentModel = new publishCommentModel()

  aboutToAppear(): void {
    Logger.info(TAG, `wyj-aboutToAppear`)
    this.listener?.on("change", (mediaQueryResult) => {
      Logger.info(TAG, `change;${mediaQueryResult.matches}`)
      if (mediaQueryResult?.matches) {
        this.displayDirection = DisplayDirection.VIDEO_HORIZONTAL
      } else {
        this.displayDirection = DisplayDirection.VERTICAL
      }
      WindowModel.shared.setMainWindowFullScreen(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL)
    })
    this.getLiveDetails()
    this.getLiveRoomData()
    this.getContentDetail()
  }

  build() {
    Column() {
      TopPlayComponent({ playerController: this.playerController })
        .layoutWeight(211)
      TabComponent({ tabs: this.tabs })
        .layoutWeight(503)
        .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)

      OperRowListView({
        operationButtonList: ['comment', 'collect', 'share', 'like'],
        contentDetailData: this.contentDetailData,
        publishCommentModel: this.publishCommentModel,
      })
        .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)


      // LiveCommentComponent({ heartNum: this.liveRoomDataBean.likeNum })
      //   .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
    }
    .height('100%')
    .width('100%')
  }

  aboutToDisappear(): void {
    Logger.info(TAG, `wyj-aboutToDisappear`)
    this.playerController?.stop()
    this.playerController?.release()
  }

  onPageShowCus(): void {
    Logger.info(TAG, `wyj-onPageShowCus`)
    // WindowModel.shared.setPreferredOrientation(window.Orientation.LOCKED);
  }

  onPageHideCus(): void {
    Logger.info(TAG, `wyj-onPageHideCus`)
    this.listener.off('change');
    // devicePLSensorManager.devicePLSensorOff();
  }

  onBackPressCus(): boolean | void {
    if (this.displayDirection == DisplayDirection.VERTICAL) {
      router.back()
    } else {
      this.displayDirection = DisplayDirection.VERTICAL
    }
    WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
    window.Orientation.PORTRAIT :
    window.Orientation.LANDSCAPE)
    // devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
    // window.Orientation.PORTRAIT :
    // window.Orientation.LANDSCAPE);
    return true
  }

  /**
   * 查询视频详情用于评论展示
   */
  getContentDetail() {
    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) {
            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)
          }
        }
      })
  }

  getLiveDetails() {
    this.liveViewModel.getLiveDetails(this.contentId, this.relId, this.relType)
      .then(
        (data) => {
          if (data.length > 0) {
            if (data[0].liveInfo?.liveState == 'wait') {
              //直播样式 0-正常模式 , 1-隐藏直播间,2-隐藏大家聊 【人民号发布是竖屏的,为空】
              if (data[0].liveInfo?.liveStyle == 1) {
                this.tabs = ['简介', '大家聊']
              } else if (data[0].liveInfo?.liveStyle == 2) {
                this.tabs = ['简介', '直播间',]
              } else {
                this.tabs = ['简介', '直播间', '大家聊']
              }
            } else {
              this.tabs = ['直播间', '大家聊']
            }
            this.liveDetailsBean = data[0]
          }
        },
        () => {

        })
  }

  getLiveRoomData() {
    this.liveViewModel.getLiveRoomData(this.contentId)
      .then(
        (data) => {
          this.liveRoomDataBean = data
        },
        () => {

        })
  }
}