mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 20:12:48 +00:00
perf: 优化草稿消息
This commit is contained in:
parent
c8364ed17b
commit
38eaf2eb02
35
resources/assets/js/store/actions.js
vendored
35
resources/assets/js/store/actions.js
vendored
@ -3,7 +3,7 @@ import {initLanguage, languageList, languageName} from "../language";
|
|||||||
import {$callData, $urlSafe, SSEClient} from './utils'
|
import {$callData, $urlSafe, SSEClient} from './utils'
|
||||||
import emitter from "./events";
|
import emitter from "./events";
|
||||||
|
|
||||||
const saveDraftTimers = {}
|
const dialogDraftState = { timer: {}, subTemp: null }
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
@ -1001,6 +1001,12 @@ export default {
|
|||||||
loading: false,
|
loading: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// 特殊处理dialogDrafts
|
||||||
|
state.dialogDrafts = state.dialogDrafts.filter(item => !!item.content).map(item => ({
|
||||||
|
...item,
|
||||||
|
tag: !!item.content,
|
||||||
|
}));
|
||||||
|
|
||||||
// TranslationLanguage检查
|
// TranslationLanguage检查
|
||||||
if (typeof languageList[state.cacheTranslationLanguage] === "undefined") {
|
if (typeof languageList[state.cacheTranslationLanguage] === "undefined") {
|
||||||
state.cacheTranslationLanguage = languageName;
|
state.cacheTranslationLanguage = languageName;
|
||||||
@ -1029,12 +1035,11 @@ export default {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Electron 页面卸载触发
|
* Electron 页面卸载触发
|
||||||
* @param commit
|
|
||||||
*/
|
*/
|
||||||
onBeforeUnload({commit}) {
|
onBeforeUnload() {
|
||||||
if ($A.isSubElectron && $A.isJson(window.__dialogDraft)) {
|
if ($A.isSubElectron && dialogDraftState.subTemp) {
|
||||||
commit('SET_DIALOG_DRAFT', window.__dialogDraft)
|
$A.execMainDispatch("saveDialogDraft", dialogDraftState.subTemp)
|
||||||
window.__dialogDraft = null;
|
dialogDraftState.subTemp = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -3181,25 +3186,25 @@ export default {
|
|||||||
* @param commit
|
* @param commit
|
||||||
* @param id
|
* @param id
|
||||||
* @param content
|
* @param content
|
||||||
|
* @param immediate
|
||||||
*/
|
*/
|
||||||
saveDialogDraft({commit}, {id, content}) {
|
saveDialogDraft({commit}, {id, content, immediate = false}) {
|
||||||
if ($A.isSubElectron) {
|
if ($A.isSubElectron) {
|
||||||
window.__dialogDraft = {id, content}
|
dialogDraftState.subTemp = {id, content, immediate: true}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除已有的计时器
|
// 清除已有的计时器
|
||||||
if (saveDraftTimers[id]) {
|
if (dialogDraftState.timer[id]) {
|
||||||
clearTimeout(saveDraftTimers[id])
|
clearTimeout(dialogDraftState.timer[id])
|
||||||
delete saveDraftTimers[id]
|
delete dialogDraftState.timer[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建新的计时器
|
// 创建新的计时器
|
||||||
saveDraftTimers[id] = setTimeout(() => {
|
dialogDraftState.timer[id] = setTimeout(() => {
|
||||||
commit('SET_DIALOG_DRAFT', {id, content})
|
commit('SET_DIALOG_DRAFT', {id, content})
|
||||||
delete saveDraftTimers[id]
|
delete dialogDraftState.timer[id]
|
||||||
resolve()
|
}, (immediate || !content) ? 0 : 600)
|
||||||
}, content ? 600 : 0)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/** *****************************************************************************************/
|
/** *****************************************************************************************/
|
||||||
|
|||||||
17
resources/assets/js/store/mutations.js
vendored
17
resources/assets/js/store/mutations.js
vendored
@ -7,14 +7,22 @@ export default {
|
|||||||
content: $A.filterInvalidLine(content),
|
content: $A.filterInvalidLine(content),
|
||||||
time: new Date().getTime()
|
time: new Date().getTime()
|
||||||
}
|
}
|
||||||
|
if (index === -1 && !item.content) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 草稿标签
|
||||||
|
if (state.dialogId == id) {
|
||||||
|
item.tag = index !== -1 ? state.dialogDrafts[index].tag : false
|
||||||
|
} else {
|
||||||
|
item.tag = !!item.content
|
||||||
|
}
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// 更新已存在的草稿
|
// 更新已存在的草稿
|
||||||
item.tag = state.dialogDrafts[index].tag
|
|
||||||
state.dialogDrafts.splice(index, 1, item)
|
state.dialogDrafts.splice(index, 1, item)
|
||||||
} else {
|
} else {
|
||||||
// 添加新草稿
|
// 添加新草稿
|
||||||
item.tag = state.dialogId != id
|
|
||||||
state.dialogDrafts.push(item)
|
state.dialogDrafts.push(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,8 +30,11 @@ export default {
|
|||||||
$A.IDBSave("dialogDrafts", state.dialogDrafts)
|
$A.IDBSave("dialogDrafts", state.dialogDrafts)
|
||||||
},
|
},
|
||||||
|
|
||||||
// 显示草稿标签
|
// 草稿标签
|
||||||
TAG_DIALOG_DRAFT(state, id) {
|
TAG_DIALOG_DRAFT(state, id) {
|
||||||
|
if (state.dialogId == id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const index = state.dialogDrafts.findIndex(item => item.id === id)
|
const index = state.dialogDrafts.findIndex(item => item.id === id)
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
state.dialogDrafts[index].tag = !!state.dialogDrafts[index].content
|
state.dialogDrafts[index].tag = !!state.dialogDrafts[index].content
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user