ProcessUtils.ets 10.3 KB
import { Action, ContentDTO, Params, PhotoListBean, commentInfo } from 'wdBean';
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO';
import { Logger } from 'wdKit';
import { StringUtils } from 'wdKit/src/main/ets/utils/StringUtils';
import { WDRouterRule } from '../router/WDRouterRule';
import { ContentConstants } from 'wdConstant';
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean';
import { AdvertsBean } from 'wdBean/src/main/ets/bean/adv/AdvertsBean';

// import { LiveModel } from '../viewmodel/LiveModel';

const TAG = 'ProcessUtils';

/**
 * 页面跳转业务封装
 */
export class ProcessUtils {
  /**
   *  广告中心的业务广告跳转方法( 现用在挂角广告)
   * @param advContent
   */
  static openAdvDetail(matInfo: CompAdvMatInfoBean) {

    if (matInfo == null) {
      return;
    }

    // 优先openType,再取linkType
    let type: string;
    if (!StringUtils.isEmpty(matInfo.openType)) {
      type = matInfo.openType;
    } else {
      type = matInfo.linkType;
    }

    if ('0' == type) {
      // 0 :无链接
      return;
    }

    let linkUrl: string = matInfo.linkUrl;
    if (StringUtils.isEmpty(linkUrl)) {
      return;
    }

    if ('1' == type) {
      // 内链
      let content: ContentDTO = {} as ContentDTO;
      content.linkUrl = linkUrl;
      ProcessUtils.gotoWeb(content);
    } else if ('2' == type) {
      // 外链
      ProcessUtils.jumpExternalWebPage(linkUrl);
    }

  }


  /**
   *   展现中心的广告跳转 ( 现用在挂角广告)
   * @param advert 展现中心的展现广告
   */
  static advJumpMainPage(advert: AdvertsBean) {

    let content: ContentDTO = {
      linkUrl: advert.linkUrl,
      pageId: advert.pageId,
      objectId: advert.objectId,
      objectType: advert.objectType,
      relId: advert.relId,
      bottomNavId: advert.bottomNavId
    } as ContentDTO;

    ProcessUtils.processPage(content);
  }

  /**
   * 页面跳转
   */
  static processPage(content: ContentDTO) {
    if (content == null) {
      Logger.error(TAG, "processPage, content is null");
      return;
    }
    if (StringUtils.isEmpty(content.objectType)) {
      Logger.error(TAG, "processPage, objectType is empty");
      return;
    }
    let type = content.objectType;
    console.log(TAG, 'objectType', `${JSON.stringify(content)}`);
    switch (type) {
      case ContentConstants.TYPE_NONE:
        Logger.debug(TAG, "processPage, do nothing");
        break;
      case ContentConstants.TYPE_VOD:
        Logger.debug(TAG, "processPage, nonsupport!!!");
        ProcessUtils.gotoVod(content)
        break;
      case ContentConstants.TYPE_LIVE:
        ProcessUtils.gotoLive(content)
        break
      case ContentConstants.TYPE_AUDIO:
        ProcessUtils.gotoAudio(content)
        break;
      case ContentConstants.TYPE_TELETEXT:
      // 图文详情,跳转h5
        ProcessUtils.gotoWeb(content);
        break;
      case ContentConstants.TYPE_LINK:
        ProcessUtils.gotoDefaultWeb(content);
        break;
    //图集详情页
      case ContentConstants.TYPE_NINE:
        ProcessUtils.gotoAtlasDetailPage(content);
        break;
      case ContentConstants.TYPE_SPECIAL_TOPIC:
      // 专题详情,跳转h5
        ProcessUtils.gotoSpecialTopic(content);
        break;
    //动态详情页(动态图文)
      case ContentConstants.TYPE_FOURTEEN:
        ProcessUtils.gotoDynamicDetailPage(content);
    //动态详情页(动态视频)
      case ContentConstants.TYPE_FIFTEEN:
        ProcessUtils.gotoDynamicDetailPage(content);
        break;
      case ContentConstants.TYPE_THIRTY:
        ProcessUtils.gotoThemeListPage(content)
        break;
      default:
        break;
    }
  }

  /**
   * 动态详情页(动态视频/动态图片)
   * @param content
   * */
  public static gotoDynamicDetailPage(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: Number.parseInt(content.objectType),
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoDynamicDetailPage, ${content.objectId}`);
  }

  /**
   * 图集详情页
   * @param content
   * */
  public static gotoMultiPictureListPage(photoList: PhotoListBean[]) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 18,
        extra: {
          photoList
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoMultiPictureListPage`);
  }

  public static gotoSpecialTopic(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        url: content.linkUrl,
        pageID: 'SPACIAL_TOPIC_PAGE',
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
  }

  public static gotoDefaultWeb(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_H5_BY_WEB_VIEW',
      params: {
        url: content.linkUrl,
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoWeb, ${content.objectId}`);
  }

  static commentGotoWeb(content: commentInfo) {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        contentID: content?.newsId,
        pageID: 'IMAGE_TEXT_DETAIL',
        extra: {
          relType: content?.relType,
          relId: content?.relId,
          sourcePage: '5',
          commentId: content?.commentId
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `commentGotoWeb, ${content.newsId}`);
  }

  public static gotoWeb(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        contentID: content?.objectId,
        pageID: 'IMAGE_TEXT_DETAIL',
        extra: {
          relType: content?.relType,
          relId: content?.relId,
          channelId: content?.channelId,
          sourcePage: '5',
          commentId: content?.commentInfo?.commentId
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoWeb, ${content.objectId}`);
  }

  public static gotoVod(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 7,
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoVod, ${content.objectId}`);
  }

  public static async gotoLive(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 2,
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoLive, ${content.objectId}`);
  }

  public static gotoAudio(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 13,
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoAudio, ${content.objectId}`);
  }

  /**
   * 金刚位聚合页
   * @param content
   * */
  public static gotoThemeListPage(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 30,
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoAtlasDetailPage, ${content.objectId}`);
  }

  /**
   * 图片预览页
   * @param content
   * */
  public static gotoAtlasDetailPage(content: ContentDTO) {
    let taskAction: Action = {
      type: 'JUMP_DETAIL_PAGE',
      params: {
        detailPageType: 17,
        contentID: content?.objectId,
        extra: {
          relType: content?.relType,
          relId: content?.relId,
        } as ExtraDTO
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
    Logger.debug(TAG, `gotoAtlasDetailPage, ${content.objectId}`);
  }

  /**
   * 打开外链
   * @param url 外链地址
   */
  public static jumpExternalWebPage(url: string) {
    let context = getContext() as common.UIAbilityContext;
    let wantInfo: Want = {
      action: 'ohos.want.action.viewData',
      entities: ['entity.system.browsable'],
      uri: url
    }
    context.startAbility(wantInfo).then(() => {
      Logger.debug(TAG, 'jumpExternalWebPage success')
    }).catch((err: BusinessError) => {
      Logger.error(TAG, 'jumpExternalWebPage success, error: ' + JSON.stringify(err))
    })
  }

  /**
   * 打开端内web页面
   * @param url web地址
   */
  public static gotoDefaultWebPage(url: string) {
    let taskAction: Action = {
      type: 'JUMP_H5_BY_WEB_VIEW',
      params: {
        url: url,
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
  }

  /**
   * 打开早晚报
   */
  public static gotoMorningEveningPaper() {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        pageID: 'MorningEveningPaper'
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
  }

  /**
   * 打开电子报
   */
  public static gotoENewsPaper() {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        pageID: 'E_NEWSPAPER'
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
  }

  /**
   * 打开播报
   */
  public static gotoBroadcastPage(pageId: number) {
    let taskAction: Action = {
      type: 'JUMP_INNER_NEW_PAGE',
      params: {
        pageID: 'BroadcastPage',
        id: pageId
      } as Params,
    };
    WDRouterRule.jumpWithAction(taskAction)
  }
}