我有一个 SAP Fiori 应用程序,我需要获取当前登录的用户详细信息。 我在网上搜索过但无法找到解决方案。
有什么方法可以从启动板获取当前登录的用户详细信息。
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);
}));
},
}
为了与当前的最佳实践保持一致,避免直接调用
sap.ushell.Container.getService
!请使用 getServiceAsync
来代替。
或者:有关当前用户的信息也可以通过应用程序路由器从 SAP 业务技术平台 (SAP BTP) 公开的用户 API服务检索。
* 如果应用程序部署到旧的 Neo 环境,请参阅 之前的编辑。
User-ID 可以从 SDK 中检索。 请参考 类 sap.ushell.services.UserInfo
试试这个:
new sap.ushell.services.UserInfo().getId()
如果您想在启动板中运行应用程序时访问用户详细信息。然后您可以通过添加以下代码片段来检索当前用户详细信息:
var userInfo = sap.ushell.Container.getService("UserInfo");
var email = userInfo.getEmail();
然后可以检索有关用户的更多详细信息,例如电子邮件和全名。请参阅 API 此处。