我正在 Neo 环境中开发 Sap Fiori 应用程序,用于填写调查问卷。 问题是,如果用户打开同一个应用程序的 2 个选项卡,则答案以及最终结果的计算都会错误地存储在调查问卷数据库中。 我想要的是,如果用户在同一浏览器的另一个选项卡中打开同一页面(或者甚至在另一个浏览器上,如果可能的话),以检查是否已经存在活动会话并中断新会话的执行。
考虑到该应用程序还调用部署在 Cloud Foundry 上的 Nodejs 服务,并且部署在 SAP BTP 上的此 Web 应用程序的打开是通过 SuccessFactors 完成的: -有没有办法能够在javascript中控制新会话的打开? (我更喜欢的解决方案) -如果不是,还有什么替代方案?
提前感谢您的回答。
我尝试过检查cookie、其他打开选项卡的URL,尝试检查历史记录,但没有任何具体结果,它们看起来仍然不是很好的解决方案。
任何跨浏览器工作的解决方案都将依赖于该锁定系统后端实现的某些东西。您需要检查调查问卷开头和结尾的后端才能采取相应的行动。
如果这不是一个选项,我建议使用浏览器的本地存储作为此锁定存储库。您可以为浏览器窗口指定一个随机名称,并将一些元数据与其一起存储。在这种情况下,在其他浏览器或私人选项卡中打开应用程序将绕过锁定。
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/util/Storage",
"sap/m/MessageBox"
], (Controller, Storage, MessageBox) => {
"use strict";
return Controller.extend("yourapp.controller.App", {
onInit: function() {
// Give the current tab a random name
window.name = +((Math.random() * 10).toFixed(2))
// Initialize local storage with app namesapce
var oMyStorage = new Storage(Storage.Type.local, "app");
// Read current local storage
var sCurrentData = oMyStorage.get("activeTab") || "{}";
var oCurrentData = JSON.parse(sCurrentData)
// Other validations can be done like checking how recent the other window was opened or
// add an option to unlock/refresh the local storage
if (sCurrentData && window.name != oCurrentData.activeTab) {
MessageBox.error(`There is an active tab opened at ${oCurrentData.openedAt}`)
return;
}
// in case no data is found, add data on local storage
var oStorageData = {
activeTab: window.name,
openedAt: new Date()
}
oMyStorage.put("activeTab", JSON.stringify(oStorageData));
},
});
});