CompParser.ets 10.3 KB
import { CompDTO, ContentDTO } from 'wdBean';
import { CommonConstants, CompStyle } from 'wdConstant/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import PageModel from '../viewmodel/PageModel';
import { CardParser } from './CardParser';
import { Card2Component } from './cardview/Card2Component';
import { Card3Component } from './cardview/Card3Component';
import { Card9Component } from './cardview/Card9Component';
import { Card6Component } from './cardview/Card6Component';
import { Card5Component } from './cardview/Card5Component';
import { AdvCardParser } from './cardViewAdv/AdvCardParser';
import { ZhCarouselLayout01 } from './compview/ZhCarouselLayout01';
import { CompNormalTitle } from './compview/CompNormalTitle';
import { ZhGridLayout02NewsContent } from './compview/ZhGridLayout02NewsContent';
import { ZhGridLayout03 } from './compview/ZhGridLayout03';
import { ZhSingleColumn04 } from './compview/ZhSingleColumn04';
import { ZhSingleColumn05 } from './compview/ZhSingleColumn05';
import { ZhSingleColumn09 } from './compview/ZhSingleColumn09';
import { ZhSingleRow02 } from './compview/ZhSingleRow02';
import { ZhSingleRow03 } from './compview/ZhSingleRow03';
import { ZhSingleRow04 } from './compview/ZhSingleRow04';
import { ZhSingleRow06 } from './compview/ZhSingleRow06';
import {
  HorizontalStrokeCardThreeTwoRadioForMoreComponent
} from './view/HorizontalStrokeCardThreeTwoRadioForMoreComponent';
import {
  HorizontalStrokeCardThreeTwoRadioForOneComponent
} from './view/HorizontalStrokeCardThreeTwoRadioForOneComponent';
import { LabelComponent } from './view/LabelComponent';
import { LiveHorizontalCardComponent } from './view/LiveHorizontalCardComponent';

/**
 * comp适配器.
 * 首页楼层comp解析器.
 */
@Component
export struct CompParser {
  @State pageId: string = '';
  @State pageName: string = '';
  @ObjectLink compDTO: CompDTO
  @State compIndex: number = 0;
  @State private pageModel: PageModel = new PageModel();
  @State audioItems: ContentDTO[] = [];
  @State noneAudioItems: ContentDTO[] = [];

  aboutToAppear(): void {

    console.log('CompParser', JSON.stringify(this.compDTO))
    this.pageName = this.pageModel.pageInfo.name
    // 轮播图屏蔽音频类型稿件
    if (this.compDTO.compStyle === CompStyle.Zh_Carousel_Layout_01) {
      this.audioItems = this.compDTO.operDataList.filter(item => {
        return item.objectType === '13' || item.linkUrl.includes('audiotopic')
      })
      this.noneAudioItems = this.compDTO.operDataList.filter(item => {
        return item.objectType !== '13' && !item.linkUrl.includes('audiotopic')
      })
      this.compDTO.operDataList = this.noneAudioItems;
    }
    // 金刚卡屏蔽音频类型稿件
     if (this.compDTO.compStyle === CompStyle.Zh_Grid_Layout_03) {
      this.audioItems = this.compDTO.operDataList.filter(item => {
        return item.objectType === '13' || item.linkUrl.includes('audiotopic')
      })
      this.noneAudioItems = this.compDTO.operDataList.filter(item => {
        return item.objectType !== '13' && !item.linkUrl.includes('audiotopic')
      })
      this.compDTO.operDataList = this.noneAudioItems;
    }
  }

  build() {
    Column() {
      //Text(JSON.stringify(this.compDTO.compStyle))
      this.componentBuilder();
    }
  }

  @Builder
  componentBuilder() {

    if (this.compDTO.operDataList[0]?.objectType !== '3' &&
      this.compDTO.operDataList[0]?.objectType !== '13') { //暂时屏蔽活动和音频详情入口
      if (this.compDTO.compStyle === CompStyle.Label_03) {
        LabelComponent({ compDTO: this.compDTO })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Carousel_Layout_01) {
        if (this.compDTO.operDataList.length > this.audioItems.length) {
          ZhCarouselLayout01({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
          Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
        }
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_01 &&
        this.compDTO.imageScale === 2) { // && compDTO.name ==="横划卡"

        LiveHorizontalCardComponent({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_01 && this.compDTO.imageScale === 3) {
        if (this.compDTO.operDataList.length > 1) {
          HorizontalStrokeCardThreeTwoRadioForMoreComponent({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        } else {
          HorizontalStrokeCardThreeTwoRadioForOneComponent({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        }
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_02) {
        ZhSingleRow02({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_03) {
        ZhSingleRow03({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Grid_Layout_02) { //双列流小视频,一行两图卡 ->标题
        //ZhGridLayout02({ compDTO: this.compDTO })
        CompNormalTitle({ compDTO: this.compDTO })
        //   Divider().strokeWidth(5).color('#f5f5f5').padding({ left: 0, right: 0 })
      } else if (this.compDTO.compStyle === CompStyle.Card_Comp_Zh_Grid_Layout_02) { //双列流小视频,一行两图卡

        ZhGridLayout02NewsContent({ compDTO: this.compDTO, operDataList: this.compDTO.operDataList, pageId: this.pageId, pageName: this.pageName })

      } else if (this.compDTO.compStyle === CompStyle.Zh_Grid_Layout_03) {
        ZhGridLayout03({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_04) {
        ZhSingleRow04({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_05) {
        // ZhSingleRow05({ compDTO })
        // Divider().strokeWidth(5).color('#f5f5f5').padding({ left: 0, right: 0 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_06) {
        ZhSingleRow06({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Column_02) {
        //头图卡 和comStyle 2相同,
        Card5Component({
          compDTO: this.compDTO,
          contentDTO: this.compDTO.operDataList[0],
          titleShowPolicy: this.compDTO.titleShowPolicy,
          pageId: this.pageId,
          pageName: this.pageName
        })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Column_03) {
        // 大图卡
        Card2Component({ compDTO: this.compDTO, contentDTO: this.compDTO.operDataList[0], pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Card_09) {
        //时间链卡
        Card9Component({
          compDTO: this.compDTO,
          contentDTO:this.compDTO.operDataList[0],
          pageId: this.pageId,
          pageName: this.pageName
        })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if(this.compDTO.compStyle === CompStyle.Card_13){
        Card6Component({ compDTO: this.compDTO, contentDTO: this.compDTO.operDataList[0], pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if(this.compDTO.compStyle === CompStyle.Card_03){
        Card3Component({ compDTO: this.compDTO, contentDTO: this.compDTO.operDataList[0], pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      }else if (this.compDTO.compStyle === CompStyle.Zh_Single_Column_04) {
        ZhSingleColumn04({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Column_05) {
        // ZhSingleColumn05({ compDTO: compDTO })
        // Divider().strokeWidth(5).color('#f5f5f5').padding({ left: 0, right: 0 })
      } else if (this.compDTO.compStyle === CompStyle.Zh_Single_Column_09) {
        ZhSingleColumn09({ compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (this.compDTO.compStyle === CompStyle.Card_Comp_Adv) { // 广告
        AdvCardParser({ pageModel: this.pageModel, compDTO: this.compDTO })
        //Text(`compIndex = ${compIndex}`).width('100%').fontSize('12fp').fontColor(Color.Red).padding({ left: 0, right: 0 })
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else if (!Number.isNaN(Number(this.compDTO.compStyle)) || this.compDTO.compType === 'appStyle') {
        CardParser({ contentDTO: this.compDTO.operDataList[0], compDTO: this.compDTO, pageId: this.pageId, pageName: this.pageName });
        Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
      } else {
        // Text(this.compDTO.compStyle)
        //   .width(CommonConstants.FULL_PARENT)
        //   .padding(10)
        //   .onClick(() => {
        //     if (this.compDTO.compStyle === CompStyle.Zh_Single_Row_06) { //精选评论
        //       WDRouterRule.jumpWithPage(WDRouterPage.QualityCommentsPage)
        //     }
        //   })
        // Divider().strokeWidth(8).color('#f5f5f5').padding({ left: 0, right: 0 })
      }
    }

  }
}