简体   繁体   English

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

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

I've a SAP Fiori application and I need to get the current logged in user details.我有一个 SAP Fiori 应用程序,我需要获取当前登录的用户详细信息。 I've searched web but unable to find a solution.我在网上搜索过,但找不到解决方案。

is there any way to get current logged in user details from launchpad.有什么方法可以从启动板获取当前登录的用户详细信息。

There is a UserInfo service from the FLP shell which can be retrieved like this: 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);
    }));
  },
}

To align with the current best practices, avoid calling sap.ushell.Container.getService directly!为了与当前的最佳实践保持一致,请避免直接调用sap.ushell.Container.getService

  • getService is deprecated. getService已弃用。 Use getServiceAsync instead.请改用getServiceAsync
  • Require the library instead of referencing the Container via global namespace ( sap.ushell.* ) as shown above.需要库而不是通过全局命名空间 ( sap.ushell.* ) 引用容器,如上所示。

Alternatively, information about the the current user can be also retrieved via the user API service exposed by the application router from the SAP Business Technology Platform (SAP BTP).或者,也可以通过应用程序路由器从 SAP 业务技术平台 (SAP BTP) 公开的用户 API 服务检索有关当前用户的信息。


* In case the app is deployed to the old Neo environment, see the previous edit . * 如果应用程序部署到旧的Neo环境,请参阅之前的编辑

The User-ID can be retrieved from SDK.可以从 SDK 中检索用户 ID。 Please refer to class sap.ushell.services.UserInfo请参考类 sap.ushell.services.UserInfo

试试这个:

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

If you want to access the user detail when you are running your application in launchpad.如果您想在启动板中运行应用程序时访问用户详细信息。 then you can retrieve current user detail by adding following code snippet:然后您可以通过添加以下代码片段来检索当前用户详细信息:

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

Then further detail about the user can be retrieved like email and fullname.然后可以检索有关用户的更多详细信息,例如电子邮件和全名。 See the API here .请参阅此处的 API。

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

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