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

tar*_*ppa 2 sapui5 sap-fiori sap-web-ide sap-cloud-platform sap-business-technology-platform

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

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

Bog*_*ann 5

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

{ // In Controller
  doSomethingUserDetails: async function() {
    const userInfo = await this.getUserInfoService();
    const userId = userInfo.getId(); // And since 1.86: .getEmail(), .getFirstName(), .getLastName(), .getFullName(), ... 
    // ...
  },
  
  getUserInfoService: function() {
    return new Promise(resolve => sap.ui.require([
      "sap/ushell/library" // In the future, "sap/ushell/Container" might need to be required instead. Refer to API reference.
    ], sapUshellLib => {
      const Container = sapUshellLib.Container;
      const service = Container.getServiceAsync("UserInfo"); // .getService is deprecated!
      resolve(service);
    }));
  },
}
Run Code Online (Sandbox Code Playgroud)

为了符合当前的最佳实践,请避免直接致电sap.ushell.Container.getServicegetServiceAsync代替使用。

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


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