业务难点:同一账号不限制登录人数,同一页面可能存在同一账号多人同时编辑
BroadcastChannel
- 页面A
// 广播接收器
this.channel = new BroadcastChannel("channel_name");
this.channel.addEventListener("message", this.updateContent);
...
updateContent (event) {
console.log(event.data, event.data.test);
}
- 页面B
// 发送消息
const bc = new BroadcastChannel("channel_name");
bc.postMessage({ test: 'hello world', ... });
channel_name 代表频道名称,可以是其他字符串,只需要保证页面A与页面B的的频道名称一致
document.hidden
document.addEventListener("visibilitychange", function () {
console.log(document.hidden); // 页面如果隐藏 返回true,反之返回 false
});
当其选项卡的内容变得可见或被隐藏时,会在 document 上触发 visibilitychange 事件
版本号
- 页面数据每次存储时版本号加一
- 点击保存时传入当前版本号
- 后端接口根据传入版本判断是否最新版本号
- 无论成功失败都返回最新数据+最新版本号
- 返回结果添加字段用来判断保存成功还是失败
- 成功则仅替换版本号
- 失败跳出弹框询问用户是否使用最新版本覆盖当前版本
- 确认则覆盖,取消则跳出新弹框是否使用当前页面内容作为最新版本提交
- 确认修改版本号提交,取消不做任何操作,下次提交重复上述操作