DetailPlayLivePage.ets 2.02 KB
import { Action, LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import { BottomComponent } from '../widgets/details/BottomComponent';
import { TabComponent } from '../widgets/details/TabComponent';
import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
import router from '@ohos.router';

@Entry
@Component
export struct DetailPlayLivePage {
  TAG: string = 'DetailPlayLivePage';
  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[] = ['直播间', '大家聊']

  aboutToAppear(): void {
    //https://pdapis.pdnews.cn/api/rmrb-bff-display-zh/content/zh/c/content/detail?relId=500005302448&relType=1&contentId=20000016340
    let par: Action = router.getParams() as Action;
    let params = par?.params;
    this.relId = params?.extra?.relId || '';
    this.relType = params?.extra?.relType || '';
    this.contentId = params?.contentID || '';
    this.getLiveDetails()
    this.getLiveRoomData()
  }

  build() {
    Column() {
      TopPlayComponent()
      TabComponent({ tabs: this.tabs })
      BottomComponent()
    }
    .height('100%')
    .width('100%')
  }

  onPageShow(): void {

  }

  getLiveDetails() {
    this.liveViewModel.getLiveDetails(this.contentId, this.relId, this.relType)
      .then(
        (data) => {
          if (data.length > 0) {
            if (data[0].liveInfo?.liveState == 'wait') {
              this.tabs = ['简介', '直播间', '大家聊']
            }
            this.liveDetailsBean = data[0]
          }
        },
        () => {

        })
  }

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

        })
  }

  aboutToDisappear(): void {

  }
}