Skip to content

Commit

Permalink
perf: 优化新窗口打开的任务保存机制
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 6, 2022
1 parent b9feeab commit c13f656
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
31 changes: 21 additions & 10 deletions resources/assets/js/pages/manage/components/TaskDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:rows="1"
:autosize="{ minRows: 1, maxRows: 8 }"
:maxlength="255"
@on-blur="updateData('name')"
@on-blur="updateBlur('name')"
@on-keydown="onNameKeydown"/>
</div>
<DatePicker
Expand Down Expand Up @@ -141,7 +141,7 @@
:rows="1"
:autosize="{ minRows: 1, maxRows: 8 }"
:maxlength="255"
@on-blur="updateData('name')"
@on-blur="updateBlur('name')"
@on-keydown="onNameKeydown"/>
</div>
<div class="desc">
Expand All @@ -152,7 +152,7 @@
:options="taskOptions"
:option-full="taskOptionFull"
:placeholder="$L('详细描述...')"
@on-blur="updateData('content')"
@on-blur="updateBlur('content')"
inline/>
</div>
<Form class="items" label-position="left" label-width="auto" @submit.native.prevent>
Expand Down Expand Up @@ -315,7 +315,8 @@
:key="key"
:task-id="task.id"
:open-task="task"
:main-end-at="taskDetail.end_at"/>
:main-end-at="taskDetail.end_at"
:can-update-blur="canUpdateBlur"/>
</ul>
<ul :class="['item-content', subList.length === 0 ? 'nosub' : '']">
<li>
Expand Down Expand Up @@ -452,6 +453,11 @@ export default {
mainEndAt: {
default: null
},
// 允许失去焦点更新
canUpdateBlur: {
type: Boolean,
default: true
},
},
data() {
return {
Expand Down Expand Up @@ -795,6 +801,12 @@ export default {
return isModify;
},
updateBlur(action, params) {
if (this.canUpdateBlur) {
this.updateData(action, params)
}
},
updateData(action, params) {
let successCallback = null;
switch (action) {
Expand All @@ -810,16 +822,15 @@ export default {
break;
case 'content':
const newContent = this.$refs.desc.getContent();
if (newContent == this.taskContent) {
const content = this.$refs.desc.getContent();
if (content == this.taskContent) {
return;
}
this.$set(this.taskDetail, 'content', newContent)
this.$set(this.taskDetail, 'content', content)
successCallback = () => {
let content = this.taskContents.find(({task_id}) => task_id == this.taskId)
this.$store.dispatch("saveTaskContent", {
id: content.id,
content: newContent
task_id: this.taskId,
content
})
}
break;
Expand Down
25 changes: 24 additions & 1 deletion resources/assets/js/pages/single/task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="electron-task">
<PageTitle :title="taskInfo.name"/>
<Loading v-if="loadIng > 0"/>
<TaskDetail v-else ref="taskDetail" :task-id="taskInfo.id" :open-task="taskInfo"/>
<TaskDetail v-else ref="taskDetail" :task-id="taskInfo.id" :open-task="taskInfo" :can-update-blur="canUpdateBlur"/>
</div>
</template>

Expand Down Expand Up @@ -39,16 +39,39 @@
<script>
import TaskDetail from "../manage/components/TaskDetail";
import {mapState} from "vuex";
export default {
components: {TaskDetail},
data() {
return {
loadIng: 0,
taskId: 0,
canUpdateBlur: true
}
},
mounted() {
document.addEventListener('keydown', this.shortcutEvent);
//
if (this.$isSubElectron) {
window.__onBeforeUnload = () => {
if (this.$refs.taskDetail.checkUpdate()) {
this.canUpdateBlur = false;
$A.modalConfirm({
content: '修改的内容尚未保存,真的要放弃修改吗?',
cancelText: '取消',
okText: '放弃',
onOk: () => {
this.$Electron.sendMessage('windowDestroy');
},
onCancel: () => {
this.canUpdateBlur = true;
}
});
return true
}
}
}
},
beforeDestroy() {
document.removeEventListener('keydown', this.shortcutEvent);
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,11 +1317,11 @@ export default {
$A.execMainDispatch("saveTaskContent", data)
//
if ($A.isArray(data)) {
data.forEach((msg) => {
dispatch("saveTaskContent", msg)
data.forEach(item => {
dispatch("saveTaskContent", item)
});
} else if ($A.isJson(data)) {
let index = state.taskContents.findIndex(({id}) => id == data.id);
let index = state.taskContents.findIndex(({task_id}) => task_id == data.task_id);
if (index > -1) {
state.taskContents.splice(index, 1, Object.assign({}, state.taskContents[index], data));
} else {
Expand Down

0 comments on commit c13f656

Please sign in to comment.