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

import { DetailPlayLivePage } from './DetailPlayLivePage'
import { DetailPlayVLivePage } from './DetailPlayVLivePage'

@Entry()
@Component
export struct DetailPlayLiveCommon {
  TAG: string = 'DetailPlayLiveCommon';
  private liveViewModel: LiveViewModel = new LiveViewModel()
  @State liveDetailsBean: LiveDetailsBean = {} as LiveDetailsBean
  @State liveState: string = ''
  @State liveStyle: number = -1
  @State relId: string = ''
  @State contentId: string = ''
  @State relType: string = ''

  aboutToAppear(): void {
    //https://pdapis.pdnews.cn/api/rmrb-bff-display-zh/content/zh/c/content/detail?relId=500005302448&relType=1&contentId=20000016340
    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.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({ contentId: this.contentId, relId: this.relId, relType: this.relType })
      }
    }
    .height('100%')
    .width('100%')
  }

  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
            console.error('liveDetailsBean===', JSON.stringify((this.liveDetailsBean)))
          }
        },
        () => {

        })
  }
}