SAP Spartacus CmsPage的加载逻辑

时间:2022-07-26
本文章向大家介绍SAP Spartacus CmsPage的加载逻辑,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

和培训老师讲得一样,经过了connector->adapter->service的过程:

Returns an observable with the page structure. The page structure is

  • typically loaded from a backend, but can also be returned from static
  • configuration (see CmsStructureConfigService).
    // load page by PageContext
    const httpParams = this.getPagesRequestParams(pageContext);
    return this.http
      .get(this.getPagesEndpoint(httpParams, fields), {
        headers: this.headers,
      })
      .pipe(this.converter.pipeable(CMS_PAGE_NORMALIZER));
  }

页面pagecontext由id和type组成:

这个page context作为http请求的参数:

如果没有指定请求的fields,则使用默认的DEFAULT:

/**
   * Returns a fully qualified OCC Url (including baseUrl and baseSite)
   * @param endpoint Name of the OCC endpoint key config
   * @param urlParams  URL parameters
   * @param queryParams Query parameters
   * @param scope
   */
  getUrl(
    endpoint: string,
    urlParams?: object,
    queryParams?: object,
    scope?: string
  ): string

这里取得endpointconfig:

OccEndpointsService._activeBaseSite从哪里来的?

url:https://jerry.eastus.cloudapp.azure.com:9002/occ/v211/electronics-spa/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=homepage

从url可见,pagecontext的id和type,出现在了HTTP请求的parameters里。