CardParser.ets 9.35 KB
import { CompStyle } from 'wdConstant';
import { CompDTO, ContentDTO } from 'wdBean';
import { Card2Component } from './cardview/Card2Component';
import { Card3Component } from './cardview/Card3Component';
import { Card4Component } from './cardview/Card4Component';
import { Card5Component } from './cardview/Card5Component';
import { Card6Component } from './cardview/Card6Component';
import { Card10Component } from './cardview/Card10Component';
import { Card11Component } from './cardview/Card11Component';
import { Card12Component } from './cardview/Card12Component';
import { Card14Component } from './cardview/Card14Component';
import { Card15Component } from './cardview/Card15Component';
import { Card16Component } from './cardview/Card16Component';
import { Card17Component } from './cardview/Card17Component';
import { Card19Component } from './cardview/Card19Component';
import { Card20Component } from './cardview/Card20Component';
import { Card21Component } from './cardview/Card21Component';
import { SearchContentComponent } from './cardview/SearchContentComponent';
import { DateTimeUtils, Logger } from 'wdKit/Index';
import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index';
import { LiveBigImage02Component } from './cardview/LiveBigImage02Component';
import { LiveBigImage01Component } from './cardview/LiveBigImage01Component';
import { behindDivider } from './cardCommon/behindDivider'
import PageModel from '../viewmodel/PageModel';

const TAG = "CardParser"
/**
 * card适配器,卡片样式汇总,依据ContentDTO#appStyle
 * 卡片样式,最小单元样式布局
 */
@Component
export struct CardParser {
  @Prop private loadImg: boolean = true;
  @State pageId: string = '';
  @State pageName: string = '';
  @State contentDTO: ContentDTO = new ContentDTO();
  @State compIndex: number = 0;
  @State nextCompDTO: CompDTO = new CompDTO
  @ObjectLink compDTO: CompDTO
  pageShowTime: number = 0;
  pageHideTime: number = 0;
  isPeopleShipHome: boolean = false;
  isNeedDivider:boolean = true

  aboutToAppear(): void {
    Logger.debugOptimize(TAG, () => {
      return JSON.stringify(this.contentDTO)
    })
  }

  onPageShow() {
    this.pageShowTime = DateTimeUtils.getTimeStamp()
  }

  //内容浏览Tracking
  onPageHide(): void {
    this.pageHideTime = DateTimeUtils.getTimeStamp()
    let duration = 0
    duration = Math.floor((this.pageHideTime - this.pageShowTime) / 1000)
    TrackingPageBrowse.trackCommonPageExposureEnd(TrackConstants.PageName.Customer_Personal,
      TrackConstants.PageName.Customer_Personal, duration)
  }

  build() {
    Column() {
      // Text('CardParser')
      // Text(JSON.stringify(this.contentDTO.appStyle))
      // Text(this.contentDTO.newsTitle)
      this.contentBuilder(this.contentDTO);
    }.borderRadius({
      topLeft:this.compIndex === 0 ? $r('app.float.image_border_radius'):0,
      topRight:this.compIndex === 0 ? $r('app.float.image_border_radius'):0
    })
  }

  @Builder
  getBehindDivider() {
    if(this.isNeedDivider){
      behindDivider({
        compDTO: this.compDTO,
        nextCompDTO: this.nextCompDTO,
        compIndex: this.compIndex
      })
    }
  }

  @Builder
  contentBuilder(contentDTO: ContentDTO) {
    // Card6Component({ compDTO: this.compDTO, contentDTO: this.contentDTO })
    if (!!contentDTO.contentText || !!contentDTO.zhDescription || !!contentDTO.introduction)  {
      SearchContentComponent({
        contentDTO,
        compDTO: this.compDTO,
        pageId: this.pageId,
        pageName: this.pageName,
        compIndex:this.compIndex
      })
      this.getBehindDivider()
    } else {
      if (contentDTO.appStyle === CompStyle.Card_02) {
        Card2Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_03) {
        Card3Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_04) {
        Card4Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_05) {
        Card5Component({
          compDTO: this.compDTO,
          contentDTO,
          titleShowPolicy: this.compDTO.titleShowPolicy,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_06 || contentDTO.appStyle === CompStyle.Card_13) {
        Card6Component({
          compDTO: this.compDTO,
          contentDTO: this.contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_10 || contentDTO.appStyle === CompStyle.Card_09) {
        Card10Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_11) {
        Card11Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_12) {
        Card12Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex

        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_14) {
        Card14Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_15) {
        Card15Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_16) {
        Card16Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_17) {
        Card17Component({
          compDTO: this.compDTO,
          contentDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_19) {
        Card19Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          isPeopleShipHome:this.isPeopleShipHome, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_20) {
        Card20Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          isPeopleShipHome:this.isPeopleShipHome, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_21) {
        Card21Component({
          contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_Comp_Live_Big_Image_01) {
        LiveBigImage01Component({
          contentDTO: contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          index: this.compIndex, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else if (contentDTO.appStyle === CompStyle.Card_Comp_Live_Big_Image_02) {
        LiveBigImage02Component({
          contentDTO: contentDTO,
          compDTO: this.compDTO,
          pageId: this.pageId,
          pageName: this.pageName,
          index:this.compIndex, loadImg: this.loadImg,
          compIndex:this.compIndex
        })
        this.getBehindDivider()
      } else {
        // todo:组件未实现 / Component Not Implemented
        // Text(contentDTO.appStyle)
        //   .width(CommonConstants.FULL_PARENT)
        //   .padding(10)
        // .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
      }
    }
  }
}