.wxml
bash
<page-container show="{{show}}" overlay="{{false}}" show="{{show}}" overlay-style="height:2px" custom-style="height:2px"
position="{{top}}" bind:beforeleave="beforeleave"></page-container>
.js
bash
Component({
/**
* 组件的属性列表
*/
properties: {
workflowData: Object
},
/**
* 组件的初始数据
*/
data: {
isModified:false,
show:true
},
lifetimes: {
attached() {
}
},
/**
* 组件的方法列表
*/
methods: {
beforeleave(){
if (this.data.entrySource == "tableList") {
this.showComfin()
}
},
async showComfin(){
if ( this.data.allowEdit && this.data.actionType == "edit") {
await this.checkFormModify();
if (this.data.isModified) {
wx.showModal({
title: '有修改的内容未保存',
content: '确定退出编辑?',
success: (res) => {
if (res.confirm) {
this.setData({
isModified : false,
show:true
})
wx.navigateBack({
delta: 1
});
} else if (res.cancel) {
this.setData({
isModified : false,
show:true
})
}
},
})
}else{
wx.navigateBack({
delta: 1
});
}
}else{
wx.navigateBack({
delta: 1
});
}
},
checkFormModify() {
this.selectComponent("#form").validate((valid, errors, document) => {
let documents = document
let originalDocument = this.data.document
if (originalDocument) {
console.log(originalDocument, "原有数据");
console.log(documents, "修改后的数据");
let isEq = _eq(originalDocument, documents);
if (!isEq) {
this.setData({
isModified : true
})
}
}
})
},
}
})