简体   繁体   English

带有后端调用的 SAPUI5 Launchpad 注销事件

[英]SAPUI5 Launchpad logout event with backend call

So, I found that the SAP Launchpad Container API provides an option to register a logout event with returning a promise ( https://sapui5.hana.ondemand.com/1.81.0/#/api/sap.ushell.services.Container%23methods/attachLogoutEvent ).所以,我发现 SAP Launchpad Container API 提供了一个选项来注册一个注销事件并返回一个承诺( https://sapui5.hana.ondemand.com/1.81.0/#/api/sap.ushell.services.Container %23methods/attachLogoutEvent )。 Unfortunately after the implementation I found out, that the UI5 version must be 1.81 or higher for parameter bAsync to work.不幸的是,在实施后我发现,UI5 版本必须是 1.81 或更高版本才能使参数 bAsync 工作。 In my project, we're at 1.78, so no promises for me.在我的项目中,我们是 1.78,所以对我没有任何承诺。

What's the problem?有什么问题?

I want to make a backend call in the said logout event.我想在上述注销事件中进行后端调用。 This doesn't work, since, as far as I understood my debugging, the Launchpad destroys everything just after my logout event has "finished" (= every line of code in the event has been gone through, ignoring sub-functions).这不起作用,因为据我了解我的调试,在我的注销事件“完成”(= 事件中的每一行代码都已完成,忽略子功能)后,Launchpad 会销毁所有内容。 Timeouts etc. don't work, because their calls would also be after code progressing has already finished, meaning the calls are deleted.超时等不起作用,因为它们的调用也会在代码进度已经完成之后进行,这意味着调用被删除。

What have I tried?我尝试了什么?

  • Instant backend call without sub-functions -> didn't work for the same reason as above没有子功能的即时后端调用 -> 由于与上述相同的原因而不起作用
  • Infinite while-looping until the backend call is processed -> stack overflow无限循环直到后端调用被处理 -> 堆栈溢出
  • While-looping with timeout/await -> await not allowed in strict mode, timeout didn't work because of the above issue while-looping with timeout/await -> 在严格模式下不允许等待,由于上述问题,超时不起作用

What do I think might work?我认为什么可能有效?

  • Stall code progression until the backend call has been finished停止代码进程直到后端调用完成
  • Using a completely different method to get my logic into handling the logout (eg. full custom logout)使用完全不同的方法让我的逻辑处理注销(例如完全自定义注销)
  • Ask here for further ideas在此处询问更多想法

Does anyone have an idea on how to solve the issue?有没有人知道如何解决这个问题? Thank you very much in advance.非常感谢您提前。

There was some problem with submitting my answer because of improper code formatting (which I couldn't find the reason for).由于代码格式不正确(我找不到原因),提交我的答案时出现了一些问题。 So I decided to quote it, just to make the submission of the answer work.所以我决定引用它,只是为了让答案的提交工作。

Alright, I have found a solution to this.好的,我已经找到了解决方案。 It's probably not the technically nicest, but it works and the result looks clean enough.它可能不是技术上最好的,但它可以工作并且结果看起来足够干净。 This is from a s4/Hana system, so it might not be a universal solution (eg. it doesn't consider logging off within the left-side pane which doesn't exist in my launchpad).这是来自 s4/Hana 系统,因此它可能不是通用解决方案(例如,它不考虑在我的启动板中不存在的左侧窗格中注销)。

What did I do?我做了什么?

Instead of attaching my individual logic to the Fiori logout-event I created a custom logout button with my individual logic, followed by calling the SICF logout node.我没有将我的个人逻辑附加到 Fiori 注销事件,而是使用我的个人逻辑创建了一个自定义注销按钮,然后调用 SICF 注销节点。

How did I do it?我是怎么做的?

  • Create a Launchpad plugin创建 Launchpad 插件
  • Component.js: add a new header item with custom logout function Component.js:添加带有自定义注销功能的新标题项
var oRenderer = sap.ushell.Container.getRenderer("fiori2"); oRenderer.addHeaderEndItem("sap.ushell.ui.shell.ShellHeadItem", { id : "logoutButton", icon : "sap-icon://log", tooltip : this.getModel("i18n").getResourceBundle().getText('btnLogoutTooltip'), text : this.getModel("i18n").getResourceBundle().getText('btnLogoutText'), ariaLabel : this.getModel("i18n").getResourceBundle().getText('btnLogoutAriaLabel'), press : this._logout.bind(this), }, true, false);
 _logout : function(){ this._callMyStuff(); window.location.href = "/sap/public/bc/icf/logoff"; }
  • style.css: hide original logout button (logoutBtn) in desktop (__list0...) and mobile (__list1...) to prevent skipping my logic by logging off via default logout. style.css:隐藏桌面(__list0 ...)和移动设备(__list1 ...)中的原始注销按钮(logoutBtn),以防止通过默认注销注销来跳过我的逻辑。
 #__list0-7-logoutBtn { display: none; } #__list1-7-logoutBtn { display: none; }

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

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