Skip to content

Commit

Permalink
perf: 优化修改工作流未保存关闭提示
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 28, 2022
1 parent d64fae1 commit 1ff59ae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
16 changes: 15 additions & 1 deletion resources/assets/js/components/DrawerOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
type: Boolean,
default: false
},
beforeClose: Function
},
data() {
Expand Down Expand Up @@ -136,12 +137,25 @@
},
methods: {
mask () {
mask() {
if (this.maskClosable) {
this.close()
}
},
close() {
if (!this.beforeClose) {
return this.handleClose();
}
const before = this.beforeClose();
if (before && before.then) {
before.then(this.handleClose);
} else {
this.handleClose();
}
},
handleClose () {
this.$emit("input", false)
},
escClose(e) {
Expand Down
24 changes: 23 additions & 1 deletion resources/assets/js/pages/manage/components/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@
<DrawerOverlay
v-model="workflowShow"
placement="right"
:beforeClose="workflowBeforeClose"
:size="1280">
<ProjectWorkflow v-if="workflowShow" :project-id="projectId"/>
<ProjectWorkflow ref="workflow" v-if="workflowShow" :project-id="projectId"/>
</DrawerOverlay>

<!--查看项目动态-->
Expand Down Expand Up @@ -1179,6 +1180,27 @@ export default {
this.$store.dispatch('toggleProjectParameter', 'completedTask');
},
workflowBeforeClose() {
return new Promise(resolve => {
if (!this.$refs.workflow.existDiff()) {
resolve()
return
}
$A.modalConfirm({
content: '设置尚未保存,是否放弃修改?',
cancelText: '放弃',
okText: '保存',
onCancel: () => {
resolve()
},
onOk: () => {
this.$refs.workflow.saveAll()
resolve()
}
});
})
},
myFilter(task, chackCompleted = true) {
if (task.archived_at) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions resources/assets/js/pages/manage/components/ProjectWorkflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export default {
return JSON.stringify(project_flow_item) != project_flow_bak
},
existDiff() {
return !!this.list.find(data => {
return this.contrast(data.project_flow_item, data.project_flow_bak)
});
},
onCreate() {
let id = -1 * $A.randNum(1000, 10000);
this.list.push({
Expand Down Expand Up @@ -468,6 +474,14 @@ export default {
$A.modalError(msg);
});
},
saveAll() {
this.list.some(data => {
if (this.contrast(data.project_flow_item, data.project_flow_bak)) {
this.onSave(data)
}
});
},
}
}
</script>

0 comments on commit 1ff59ae

Please sign in to comment.