|
@@ -176,12 +176,47 @@ export default {
|
|
|
isOpenCloseItems: true, // 是否展开方案配置项
|
|
|
isDownLight: -1,
|
|
|
isTopLight: -1,
|
|
|
- flag: 1
|
|
|
+ flag: 1,
|
|
|
+ editCount: -1, // 页面会否被编辑 >0被编辑 =0 未编辑
|
|
|
+ isSaveSuccess: false // 是否保存成功
|
|
|
};
|
|
|
},
|
|
|
+ beforeRouteLeave(to, from, next) {
|
|
|
+ if (
|
|
|
+ (this.editCount > 2 && !this.isSaveSuccess && this.isEdit) ||
|
|
|
+ (this.editCount > 1 && !this.isSaveSuccess && !this.isEdit)
|
|
|
+ ) {
|
|
|
+ // console.log('页面被编辑了');
|
|
|
+ this.$confirm('还有未保存的内容,确定要退出当前页面吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ cancelButtonClass: 'leaveBtn',
|
|
|
+ customClass: 'leaveBox',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ next();
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ } else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ },
|
|
|
watch: {
|
|
|
+ form: {
|
|
|
+ handler(newName, oldName) {
|
|
|
+ this.editCount++;
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ // immediate: true
|
|
|
+ },
|
|
|
planDefaultList: {
|
|
|
- handler(newName, oldName) {},
|
|
|
+ handler(newName, oldName) {
|
|
|
+ // console.log(newName,'newName');
|
|
|
+ // console.log(oldName,'oldName');
|
|
|
+ this.editCount++;
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
immediate: true
|
|
|
}
|
|
|
},
|
|
@@ -419,10 +454,11 @@ export default {
|
|
|
if (res.data.code === '0') {
|
|
|
this.$message({
|
|
|
showClose: true,
|
|
|
- message: this.isEdit ? '编辑成功' : '添加成功',
|
|
|
+ message: '保存成功',
|
|
|
type: 'success',
|
|
|
duration: 1000
|
|
|
});
|
|
|
+ this.isSaveSuccess = true; // 保存成功,可正常退出
|
|
|
this.$router.push({
|
|
|
name: 'Plan',
|
|
|
params: Object.assign({}, this.$route.params, {
|
|
@@ -560,4 +596,11 @@ export default {
|
|
|
margin-top: 12px;
|
|
|
}
|
|
|
}
|
|
|
+.leaveBox {
|
|
|
+ /deep/ .leaveBtn {
|
|
|
+ // margin-right: 46px;
|
|
|
+ background-color: #d7d7d7 !important;
|
|
|
+ border-color: transparent;
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|