如何在 UI5 1.38 中重用另一个应用程序的组件?

Syl*_*kFr 7 sapui5 sap-fiori sap-web-ide sap-cloud-platform

环境

框架:SAPUI5 V1.38.39
IDE:SAP WEB IDE

问题

我想在另一个应用程序中使用 SAPUI5 应用程序,为此我找到了以下资源:https ://blogs.sap.com/2017/04/05/sapui5-how-to-reuse-parts-of- a-sapui5-application-in-othermultiple-sapui5-applications/

来自我想重用另一个应用程序的代码

在 init 中的 component.js 中我使用了:

var sPath = sHostUrl.includes("webidetesting") ? "https://gtyext.net" : sHostUrl;
jQuery.sap.registerModulePath("ztntapp", `${sPath}/sap/bc/ui5_ui5/sap/ztntapp/`);
Run Code Online (Sandbox Code Playgroud)

在我看来:

<core:ComponentContainer 
    name="ztntapp" 
    manifestFirst="true" 
    component="ztntapp">
</core:ComponentContainer>
Run Code Online (Sandbox Code Playgroud)

并在 neo-app.json 中

{
    "path": "/sap/bc/ui5_ui5/sap/ztntapp/",
    "target": {
        "type": "destination",
        "name": "gtyext_net",
        "entryPath": "/sap/bc/ui5_ui5/sap/ztntapp/"
    },
    "description": "namespace.tntapp Resources"
}
Run Code Online (Sandbox Code Playgroud)

来自重用应用程序的代码

在 component.js 中

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/Device",
    "./model/models"
], function (UIComponent, Device, models) {
    "use strict";

    return UIComponent.extend("TrackAndTrace.ztntapp.Component", {

        metadata: {
            manifest: "json"
        },
        init: function () {
        [...]
        },
        [...]
   });
});

Run Code Online (Sandbox Code Playgroud)

在 neo-app.json 中(它是通过 SAP WebIDE 创建的默认值):

{
  "welcomeFile": "/webapp/index.html",
  "routes": [
    {
      "path": "/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/webapp/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/webapp/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Test Resources"
    }
  ],
  "sendWelcomeFileRedirect": true
}
Run Code Online (Sandbox Code Playgroud)

错误信息

未捕获的错误:无法从https://webidetesting278-a392f.dispatcher.hana.ondemand.com/sap/bc/ui5_ui5/sap/ztntapp/Component.js加载“ztntapp/Component.js” :错误:加载失败TrackAndTrace/ztntapp/model/models.js' 来自 resources/TrackAndTrace/ztntapp/model/models.js

neo-app.json 的要点:

其他研究

  • 使用 neo-app.json 文件,问题是从“ztntapp”中定位资源,我看到还有一个 jQuery.sap.registerResourcePath 但我不知道如何在这种情况下使用它

Gre*_*ski 2

在您的第一个应用程序(主应用程序)中,请使用 manifest.json 添加组件用法,而不是jQuery.sap.registerModulePath在 Component.js 中:

"componentUsages": {
    "ztntapp": {
            "name": " TrackAndTrace.ztntapp",
        "settings": {},
        "componentData": {},
        "lazy": true
    }
}
Run Code Online (Sandbox Code Playgroud)

然后您需要调整您的主应用程序 neo-app.json 以启用运行配置以到达您的第二个应用程序(重用应用程序)

"routes": [
        {
      "path": "/webapp/resources/TrackAndTrace/ztntapp",
      "target": {
        "type": "application",
        "name": "ztntapp"
      }
    },
    {
      "path": "/resources/TrackAndTrace/ztntapp",
      "target": {
        "type": "application",
        "name": "ztntapp"
      }
    },
Run Code Online (Sandbox Code Playgroud)

然后对于结果应用程序:部署您的应用程序,以便它在 SAP WebIDE Fullstack 工作区中注册。

然后,对于 WebIDE 中的主应用程序,选择“运行”>“运行配置”>“添加配置”>“作为 Web 应用程序运行”>“高级设置”,标记“首先使用我的工作区” ,然后按“获取资源版本”。在下面的列表中,您应该会看到资源名称下列出了您的重用应用程序: WebIDE配置