mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf: 优化新窗口打开的任务保存机制
This commit is contained in:
parent
b9feeabfb3
commit
c13f65611f
@ -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
|
||||
@ -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">
|
||||
@ -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>
|
||||
@ -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>
|
||||
@ -452,6 +453,11 @@ export default {
|
||||
mainEndAt: {
|
||||
default: null
|
||||
},
|
||||
// 允许失去焦点更新
|
||||
canUpdateBlur: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -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) {
|
||||
@ -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;
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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);
|
||||
|
||||
6
resources/assets/js/store/actions.js
vendored
6
resources/assets/js/store/actions.js
vendored
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user