目前有一个报告编辑功能,这个报告编辑不能同时两人编辑,一个账号进去之后就要调接口进行“上锁”,在返回或者退出登录需要“解锁”,关闭网页或者浏览器时也需要解锁,不能一直处于“上锁” 状态,但是现在在关闭网页前调用了接口,接口没有执行完,窗口关闭了,这样接口就会终止,实现不了“解锁”,该如何修改
mounted{
if (row.state == "REPORT_STATUS_EDIT") {
window.addEventListener('beforeunload', this.handleBeforeUnload);
window.addEventListener('popstate', this.handlePopState);
}
}
beforeDestroy() {
this.$api.reportManage.unlockEditReport({
reportId: this.reportId
}).then(res => {})
},
destroyed() {
window.removeEventListener("beforeunload", this.handleBeforeUnload);
window.removeEventListener("popstate", this.handlePopState);
},
beforeRouteLeave(to, from, next) {
if (this.state == "REPORT_STATUS_EDIT" && to.path != '/reportManage/editreport') {
this.$api.reportManage
.unlockEditReport({
reportId: this.reportId,
})
.then((res) => {});
}
next();
window.removeEventListener("beforeunload", this.handleBeforeUnload);
window.removeEventListener("popstate", this.handlePopState);
},
methods:{
handleBeforeUnload(event) {
// 处理用户关闭网页的逻辑
this.$api.reportManage.unlockEditReport({
reportId: this.reportId
}).then(res => {
})
},
handlePopState(event) {
if (this.state == "REPORT_STATUS_EDIT") {
// 处理用户返回上一页的逻辑
this.$api.reportManage.unlockEditReport({
reportId: this.reportId
}).then(res => {})
}
},
}