CompParser.ets 6.87 KB
import { CompDTO, ContentDTO , slideShows} 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';
import { AlbumCardComponent } from './view/AlbumCardComponent';
import { ZhSingleRow04 } from './view/ZhSingleRow04'
import { CompStyle_09 } from './view/CompStyle_09'
import { CompStyle_10 } from './view/CompStyle_10'

/**
 * comp适配器.
 */
@Preview
@Component
export struct CompParser {
  @State compDTO: CompDTO = {
    compStyle: '17',
    imageScale: 3,
    operDataList: [
      {
        title: 'title0',
        description: "description0",
        coverUrl: 'https://uatjdcdnphoto.aikan.pdnews' +
          '.cn/sjbj-20231208/image/display/d4496925a1264a749975ae9b01a4ef46.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg',
        fullColumnImgUrls: [{
          url: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20240104/image/display/c4a9b526e0994d1bbd3ac8450f5cfc6c.jpg?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
        },{
          url:'https://uatjdcdnphoto.aikan.pdnews' +
            '.cn/sjbj-20231208/image/display/d4496925a1264a749975ae9b01a4ef46.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg',
        },{
          url: 'https://uatjdcdnphoto.aikan.pdnews' +
            '.cn/sjbj-20231208/image/display/d4496925a1264a749975ae9b01a4ef46.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg',
        }]
      } as ContentDTO,
      {
        title: 'title1 title1 title1 title1 title1 title1 title1 title1 title1',
        description: "description1",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20240104/image/display/c4a9b526e0994d1bbd3ac8450f5cfc6c.jpg?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
      } as ContentDTO,
      {
        title: 'title2',
        description: "description2",
        coverUrl: "https://cdnjdphoto.aikan.pdnews.cn/sjbj-20231206/image/live/bbe6d821e92b48919d90c7dadfd1f05a.jpg?x-oss-process=image/resize,l_850/auto-orient,1/quality,q_95/format,jpg",
      } as ContentDTO,
      {
        title: 'title3',
        description: "description3",
        coverUrl: 'https://cdnjdphoto.aikan.pdnews.cn/sjbj-20231109/image/live/102e6eb9356b4ef19405b04c1f6ff875.png?x-oss-process=image/resize,l_850/auto-orient,1/quality,q_95/format,jpg'
      } as ContentDTO,
      {
        title: 'title4',
        description: "description4",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/62bdbbb35dbd45689e00790c81f04c4b.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
      } as ContentDTO,
      {
        title: 'title5',
        description: "description5",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/f79bbaa5a33b4bd88176071c4f797ff6.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
      } as ContentDTO,
      {
        title: 'title6',
        description: "description6",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231218/image/display/2c1d917009584ce2bb4a35cbb3a860a0.png?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
      } as ContentDTO,
      {
        title: 'title7',
        description: "description7",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231222/image/display/117dc516ca5c42d5843c0d32050c9fc6.jpeg?x-oss-process=image/resize,w_240/quality,q_90/format,jpg",
      } as ContentDTO,
      {
        title: 'title8',
        description: "description8",
        coverUrl: "https://uatjdcdnphoto.aikan.pdnews.cn/sjbj-20231228/image/display/90a2db4077d44a1f887f068fc659d977.jpeg?x-oss-process=image/resize,w_550/quality,q_90/format,jpg",
      } as ContentDTO
    ]
  } 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
      || compDTO.compStyle === CompStyle.Single_ImageCard_01) {
      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
      || compDTO.compStyle === '5') {
      HeadPictureCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.ZhGrid_Layout_03) {
      ZhGridLayoutComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Album_Card_01) {
      AlbumCardComponent({ compDTO: compDTO })
    } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_04) {
      ZhSingleRow04({ compDTO: compDTO})
    } else if (compDTO.compStyle === CompStyle.CompStyle_09) {
      CompStyle_09({ compDTO: compDTO})
    } else if (compDTO.compStyle === CompStyle.CompStyle_10) {
      CompStyle_10({ compDTO: compDTO})
    }
    else {
      // todo:组件未实现 / Component Not Implemented
      Text(compDTO.compStyle)
        .width(CommonConstants.FULL_PARENT)
        .padding(10)
      // .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
    }
  }
}