VideoChannelDetail.ets 3.92 KB
import { Action, ContentDetailDTO, InteractDataDTO } from 'wdBean/Index';
import { ContentDetailRequest } from 'wdDetailPlayApi/Index'
import { ResponseDTO } from 'wdNetwork/Index';
import { DetailPlayShortVideoPage } from './DetailPlayShortVideoPage'
import { Test } from './Test'
import router from '@ohos.router';
import window from '@ohos.window';
import { contentListParams } from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';

@Entry
@Component
export struct VideoChannelDetail {
  private contentId: string = ''
  private relId: string = ''
  private relType: string = ''
  private swiperController: SwiperController = new SwiperController()
  @State data: ContentDetailDTO[] = []
  @State testData: string[] = ['111', '222', '333']
  @State currentIndex: number = 0
  @State interactDataList: InteractDataDTO[] = []

  async aboutToAppear(): Promise<void> {
    let data: ContentDetailDTO[] = []
    let action: Action = router.getParams() as Action
    if (action) {
      this.contentId = action.params?.contentID || ''
      if (action.params && action.params.extra) {
        this.relId = action.params.extra.relId || ''
        this.relType = action.params.extra.relType || ''
      }
      await ContentDetailRequest.getContentDetail({
        contentId: this.contentId,
        relId: this.relId,
        relType: this.relType
      }).then((resDTO: ResponseDTO<ContentDetailDTO[]>) => {
        console.error('resDTO==', JSON.stringify(resDTO.data))
        if (resDTO.data) {
          this.data.push(resDTO.data[0])
        }

      })
    }

    await this.queryVideoList()

    // await ContentDetailRequest.postRecommendVideoList({
    //   pageSize: 5,
    //   refreshCnt: 1
    // }).then(res => {
    //   if (res.data) {
    //     data = data.concat(res.data)
    //   }
    //   console.log('res1===', JSON.stringify(res))
    //   console.log('res==' + this.data)
    // })


    if (this.data.length > 0) {
      const params: contentListParams = {
        contentList: []
      }
      this.data.map(item => {
        params.contentList.push({
          contentId: item.newsId + '',
          contentType: item.newsType
        })
      })
      // 批量查询内容当前用户点赞、收藏状态
      await ContentDetailRequest.getContentInteract(params).then(res => {
        if (res.data) {
          this.interactDataList = res.data || []
        }
        console.log('获取互动点赞等数据===', JSON.stringify(res))
      })
      // 查询各类型内容动态数据接口V2

    }

    // this.data = data
    console.error('aboutToAppear===', this.data.length)


  }

  /**
   * 查询视频列表用于翻页
   */
  async queryVideoList() {
    await ContentDetailRequest.postRecommendVideoList({
      pageSize: 5,
      refreshCnt: 1
    }).then(res => {
      if (res.data) {
        this.data = this.data.concat(res.data)
      }
      // console.log('queryVideoList===', JSON.stringify(this.data))
    })
  }

  build() {
    Column() {
      Swiper(this.swiperController) {

        ForEach(this.data, (item: ContentDetailDTO, index: number) => {
          Column() {
            DetailPlayShortVideoPage({
              contentDetailData: item,
              currentIndex: this.currentIndex,
              index: index,
              interactData: this.interactDataList[index]
            })
          }.width('100%')
          .height('100%')
        }, (item: ContentDetailDTO) => item.newsId + '')
      }
      .cachedCount(-1)
      .indicator(false)
      .vertical(true)
      .loop(false)
      .width('100%')
      .height('100%')
      // 扩展至所有非安全区域
      .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
      .onChange((index: number) => {
        this.currentIndex = index
        console.info('onChange==', index.toString())

        if (this.currentIndex === this.data.length - 1) {
          this.queryVideoList()
        }
      })

    }.width('100%').height('100%')
  }
}