繁体   English   中英

SAP Fiori 在 UI5 应用程序中获取登录的用户详细信息

[英]SAP Fiori Get logged in user details in UI5 application

我有一个 SAP Fiori 应用程序,我需要获取当前登录的用户详细信息。 我在网上搜索过,但找不到解决方案。

有什么方法可以从启动板获取当前登录的用户详细信息。

FLP shell 中有一个UserInfo服务,可以像这样检索:

{ // In Controller
  doSomethingUserDetails: async function() {
    const oUserInfo = await this.getUserInfoService();
    const sUserId = oUserInfo.getId(); // And in SAPUI5 1.86, those became public: .getEmail(), .getFirstName(), .getLastName(), .getFullName(), ... 
    // ...
  },
  
  getUserInfoService: function() {
    return new Promise(resolve => sap.ui.require([
      "sap/ushell/library"
    ], oSapUshellLib => {
      const oContainer = oSapUshellLib.Container;
      const pService = oContainer.getServiceAsync("UserInfo"); // .getService is deprecated!
      resolve(pService);
    }));
  },
}

为了与当前的最佳实践保持一致,请避免直接调用sap.ushell.Container.getService

  • getService已弃用。 请改用getServiceAsync
  • 需要库而不是通过全局命名空间 ( sap.ushell.* ) 引用容器,如上所示。

或者,也可以通过应用程序路由器从 SAP 业务技术平台 (SAP BTP) 公开的用户 API 服务检索有关当前用户的信息。


* 如果应用程序部署到旧的Neo环境,请参阅之前的编辑

可以从 SDK 中检索用户 ID。 请参考类 sap.ushell.services.UserInfo

试试这个:

new sap.ushell.services.UserInfo().getId()

如果您想在启动板中运行应用程序时访问用户详细信息。 然后您可以通过添加以下代码片段来检索当前用户详细信息:

var userInfo = sap.ushell.Container.getService("UserInfo");
var email = userInfo.getEmail();

然后可以检索有关用户的更多详细信息,例如电子邮件和全名。 请参阅此处的 API。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM