WDShare.ets 4.49 KB
import { ContentDetailDTO, ContentDTO, PageInfoDTO, ShareInfoDTO, TopicInfo } from 'wdBean/Index';
import { SharePosterItemBean } from 'wdBean/src/main/ets/bean/detail/SharePosterItemBean';
import { ShareScene, ShareType, WDShareBase } from 'wdShareBase/Index';
import { ShareContentType } from 'wdShareBase/src/main/ets/Constant';
import { bundleManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { AppInnerLinkGenerator } from 'wdRouter';

export class WDShare {

  static shareContent(content: ContentDetailDTO, pageName: string ="", pageId: string = "") {

    //TODO: 处理分享弹框交互和 海报逻辑

    WDShareBase.getInstance().share({
      to: ShareType.System,
      scene: ShareScene.System,
      type: ShareContentType.Link,
      obj: {
        title: content.shareInfo.shareTitle,
        desc: content.shareInfo.shareSummary,
        link: content.shareInfo.shareUrl,
        deeplink:AppInnerLinkGenerator.generateDeepLinkWithConent(content),
        posterImg:$r("app.media.test_share_poster"),
      }
    })
  }

  static shareProgram(program: ContentDTO, pageName: string ="", pageId: string = "") {
    //TODO: 处理分享弹框交互和 海报逻辑

    WDShareBase.getInstance().share({
      to: ShareType.System,
      scene: ShareScene.System,
      type: ShareContentType.Link,
      obj: {
        title: program.shareInfo.shareTitle,
        desc: program.shareInfo.shareSummary,
        link: program.shareInfo.shareUrl,
        deeplink:AppInnerLinkGenerator.generateDeepLinkWithProgram(program),
      }
    })
  }

  static shareSubject(subject: PageInfoDTO) {


  }

  //专题分享数据转换
  static setTopicBeanToShareBean(shareBean: ShareInfoDTO, topicInfoBean?: TopicInfo){
    shareBean.appCustomTopicType = topicInfoBean?.topicType+''
    //21:文章专题,22:音频专题,23:直播专题,24:话题专题,25:早晚报专题,26:时间链
    if(25 == topicInfoBean?.topicType){
      shareBean.appCustomShowPosterType = 6
      shareBean.appCustomTopicPattern = topicInfoBean.topicPattern
      shareBean.appCustomPublishTime = topicInfoBean.topicDate
      if(topicInfoBean.frontLinkObject == null){
        shareBean.appCustomIsFrontDaily = false
        if(topicInfoBean.shareContentList != null && topicInfoBean.shareContentList.length>0){
          shareBean.appCustomSharePosterItemList = [] as SharePosterItemBean[]
          shareBean.appCustomSharePosterItemList.length = topicInfoBean.shareContentList.length
          for (let index = 0; index < topicInfoBean.shareContentList.length; index++) {
            let  element = topicInfoBean.shareContentList[index]
            if(element != null){
              shareBean.appCustomSharePosterItemList[index] = {
                title:topicInfoBean.shareContentList[index].newsTitle,
                imageUrl:topicInfoBean.shareContentList[index].coverUrl,
              } as SharePosterItemBean
            }
          }
        }
      }else{
        shareBean.appCustomIsFrontDaily = true
        shareBean.sharePosterCoverUrl = topicInfoBean.frontLinkObject.coverUrl
        shareBean.appCustomPosterSummary = topicInfoBean.frontLinkObject.summary
      }
    }else{
      //文章/直播/话题专题(H5普通文章专题,包含时间链)
      shareBean.appCustomShowPosterType = 8
      //海报的头图
      shareBean.sharePosterCoverUrl = topicInfoBean?.backgroundImgUrl || ''
      shareBean.appCustomIsFrontDaily = false
      shareBean.appCustomPosterTitle = topicInfoBean?.title || ''
      shareBean.appCustomPosterSummary = topicInfoBean?.summary || ''
      if(topicInfoBean?.shareContentList != null && topicInfoBean?.shareContentList && topicInfoBean.shareContentList.length > 0){
        shareBean.appCustomSharePosterItemList = [] as SharePosterItemBean[]
        shareBean.appCustomSharePosterItemList.length = topicInfoBean.shareContentList.length
        for (let index = 0; index < topicInfoBean.shareContentList.length; index++) {
          let  element = topicInfoBean.shareContentList[index]
          if(element != null){
            shareBean.appCustomSharePosterItemList[index] = {
              title:topicInfoBean.shareContentList[index].newsTitle,
              imageUrl:topicInfoBean.shareContentList[index].coverUrl,
              timeNode:topicInfoBean.shareContentList[index].publishTime,
              timeBlurred:topicInfoBean.shareContentList[index].timeBlurred
            } as SharePosterItemBean
          }
        }
      }
    }
  }

}