CompParser.ets 2.92 KB
import { CompDTO } from 'wdBean';
import { CommonConstants, CompStyle } from 'wdConstant';
import { BannerComponent } from './view/BannerComponent';
import { LabelComponent } from './view/LabelComponent';
import { TitleAbbrComponent } from './view/TitleAbbrComponent';
import { TitleAllComponent } from './view/TitleAllComponent';
import { SingleImageCardComponent } from './view/SingleImageCardComponent';
import { BigPicCardComponent } from './view/BigPicCardComponent';
import { TriPicCardComponent } from './view/TriPicCardComponent';
import { LiveHorizontalCardComponent } from './view/LiveHorizontalCardComponent';
import { HeadPictureCardComponent } from './view/HeadPictureCardComponent';
import { ZhGridLayoutComponent } from './view/ZhGridLayoutComponent';
import {
  HorizontalStrokeCardThreeTwoRadioForMoreComponent
} from './view/HorizontalStrokeCardThreeTwoRadioForMoreComponent';
import {
  HorizontalStrokeCardThreeTwoRadioForOneComponent
} from './view/HorizontalStrokeCardThreeTwoRadioForOneComponent';

/**
 * comp适配器.
 */
@Component
export struct CompParser {
  compDTO: CompDTO = {} as CompDTO;
  compIndex: number = 0;

  build() {
    this.componentBuilder(this.compDTO, this.compIndex);
  }

  @Builder
  componentBuilder(compDTO: CompDTO, compIndex: number) {
    if (compDTO.compStyle === CompStyle.Label_03) {
      LabelComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Title_Abbr_01) {
      TitleAbbrComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Title_All_01) {
      TitleAllComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Carousel_Layout_01) {
      BannerComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Single_Imagecard_03) {
      SingleImageCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === "2") {
      BigPicCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === "4") {
      TriPicCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_01 && compDTO.imageScale === 2) {
      LiveHorizontalCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_01 && compDTO.imageScale === 3) {
      if (compDTO.operDataList.length > 1) {
        HorizontalStrokeCardThreeTwoRadioForMoreComponent({ compDTO: compDTO })
      } else {
        HorizontalStrokeCardThreeTwoRadioForOneComponent({ compDTO: compDTO })
      }
    } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_02) {
      HeadPictureCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.ZhGrid_Layout_03) {
      ZhGridLayoutComponent({ compDTO: compDTO })
    } else {
      // todo:组件未实现 / Component Not Implemented
      Text(compDTO.compStyle)
        .width(CommonConstants.FULL_PARENT)
        .padding(10)
      // .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
    }
  }
}