perf: 优化草稿消息

This commit is contained in:
kuaifan 2025-03-13 20:24:57 +08:00
parent 4061ae4275
commit ba52738904
7 changed files with 33 additions and 41 deletions

View File

@ -548,7 +548,7 @@ export default {
'isModKey',
]),
...mapGetters(['getDraft']),
...mapGetters(['getDialogDraft']),
isEnterSend({cacheKeyboard}) {
if (this.$isEEUiApp) {
@ -708,7 +708,7 @@ export default {
},
inputDraft() {
return this.getDraft(this.dialogId)
return this.getDialogDraft(this.dialogId)
}
},
watch: {
@ -723,10 +723,7 @@ export default {
}
}
if (!this.simpleMode) {
this.$store.dispatch("saveDraft", {
dialogId: this.dialogId,
content: val
})
this.$store.dispatch("saveDialogDraft", {id: this.dialogId, content: val})
}
},

View File

@ -1688,10 +1688,7 @@ export default {
if (!this.msgText) {
return;
}
this.$store.dispatch("saveDraft", {
dialogId: this.taskDetail.dialog_id,
content: this.msgText
})
this.$store.dispatch("saveDialogDraft", {id: this.taskDetail.dialog_id, content: this.msgText})
},
taskPasteDrag(e, type) {

View File

@ -107,9 +107,9 @@
<em v-if="dialog.last_at">{{$A.timeFormat(dialog.last_at)}}</em>
</div>
<div class="dialog-text no-dark-content">
<template v-if="dialog.id != dialogId && tagDraft(dialog.id)">
<template v-if="dialog.id != dialogId && tagDialogDraft(dialog.id)">
<div class="last-draft">[{{$L('草稿')}}]</div>
<div class="last-text"><span>{{formatDraft(getDraft(dialog.id))}}</span></div>
<div class="last-text"><span>{{formatDraft(getDialogDraft(dialog.id))}}</span></div>
</template>
<template v-else>
<template v-if="dialog.type=='group' && dialog.last_msg && dialog.last_msg.userid">
@ -363,7 +363,7 @@ export default {
'taskColorList'
]),
...mapGetters(['getDraft', 'tagDraft']),
...mapGetters(['getDialogDraft', 'tagDialogDraft']),
routeName() {
return this.$route.name
@ -740,7 +740,7 @@ export default {
return $A.sortFloat(b.todo_num, a.todo_num);
}
// 稿
const drafts = [this.tagDraft(a.id) ? 1 : 0, this.tagDraft(b.id) ? 1 : 0];
const drafts = [this.tagDialogDraft(a.id) ? 1 : 0, this.tagDialogDraft(b.id) ? 1 : 0];
if (drafts[0] || drafts[1]) {
return $A.sortFloat(drafts[1], drafts[0]);
}

View File

@ -971,11 +971,11 @@ export default {
'cacheTaskBrowse',
'cacheTranslations',
'dialogMsgs',
'dialogDrafts',
'fileLists',
'callAt',
'cacheEmojis',
'cacheDialogs',
'cacheDrafts',
],
json: [
'userInfo'
@ -1032,7 +1032,7 @@ export default {
*/
onBeforeUnload({commit}) {
if ($A.isSubElectron && $A.isJson(window.__dialogDraft)) {
commit('SET_DRAFT', window.__dialogDraft)
commit('SET_DIALOG_DRAFT', window.__dialogDraft)
window.__dialogDraft = null;
}
},
@ -3085,7 +3085,7 @@ export default {
$A.execMainDispatch("closeDialog", dialog_id)
// 更新草稿标签
commit('TAG_DRAFT', dialog_id)
commit('TAG_DIALOG_DRAFT', dialog_id)
// 关闭会话后删除会话超限消息
const msgs = state.dialogMsgs.filter(item => item.dialog_id == dialog_id)
@ -3178,15 +3178,15 @@ export default {
/**
* 保存草稿
* @param commit
* @param dialogId
* @param id
* @param content
*/
saveDraft({commit}, {dialogId, content}) {
saveDialogDraft({commit}, {id, content}) {
if ($A.isSubElectron) {
window.__dialogDraft = {dialogId, content}
window.__dialogDraft = {id, content}
return
}
commit('SET_DRAFT', {dialogId, content})
commit('SET_DIALOG_DRAFT', {id, content})
},
/** *****************************************************************************************/

View File

@ -244,8 +244,8 @@ export default {
* @param state
* @returns {function(*): *|string}
*/
getDraft: (state) => (dialogId) => {
const draft = state.cacheDrafts.find(item => item.dialogId === dialogId)
getDialogDraft: (state) => (id) => {
const draft = state.dialogDrafts.find(item => item.id === id)
return draft ? draft.content : ''
},
@ -254,8 +254,8 @@ export default {
* @param state
* @returns {function(*): boolean}
*/
tagDraft: (state) => (dialogId) => {
const draft = state.cacheDrafts.find(item => item.dialogId === dialogId)
tagDialogDraft: (state) => (id) => {
const draft = state.dialogDrafts.find(item => item.id === id)
return !!draft?.tag
},
}

View File

@ -1,33 +1,33 @@
export default {
// 设置草稿
SET_DRAFT(state, {dialogId, content}) {
const index = state.cacheDrafts.findIndex(item => item.dialogId === dialogId)
SET_DIALOG_DRAFT(state, {id, content}) {
const index = state.dialogDrafts.findIndex(item => item.id === id)
const item = {
dialogId,
id,
content: $A.filterInvalidLine(content),
time: new Date().getTime()
}
if (index !== -1) {
// 更新已存在的草稿
item.tag = state.cacheDrafts[index].tag
state.cacheDrafts.splice(index, 1, item)
item.tag = state.dialogDrafts[index].tag
state.dialogDrafts.splice(index, 1, item)
} else {
// 添加新草稿
item.tag = state.dialogId != dialogId
state.cacheDrafts.push(item)
item.tag = state.dialogId != id
state.dialogDrafts.push(item)
}
// 保存到 IndexedDB
$A.IDBSave("cacheDrafts", state.cacheDrafts)
$A.IDBSave("dialogDrafts", state.dialogDrafts)
},
// 显示草稿标签
TAG_DRAFT(state, dialogId) {
const index = state.cacheDrafts.findIndex(item => item.dialogId === dialogId)
TAG_DIALOG_DRAFT(state, id) {
const index = state.dialogDrafts.findIndex(item => item.id === id)
if (index !== -1) {
state.cacheDrafts[index].tag = !!state.cacheDrafts[index].content
$A.IDBSave("cacheDrafts", state.cacheDrafts)
state.dialogDrafts[index].tag = !!state.dialogDrafts[index].content
$A.IDBSave("dialogDrafts", state.dialogDrafts)
}
},
}

View File

@ -7,7 +7,7 @@ export default {
clientId: "",
// 缓存版本号(如果想升级后清除客户端缓存则修改此参数值)
cacheVersion: "v12",
cacheVersion: "v13",
// 窗口是否激活
windowActive: true,
@ -78,9 +78,6 @@ export default {
// Dialog
cacheDialogs: [],
// Draft
cacheDrafts: [],
// Project
cacheProjects: [],
cacheColumns: [],
@ -126,6 +123,7 @@ export default {
dialogTodos: [],
dialogMsgTops: [],
dialogHistory: [],
dialogDrafts: [],
dialogMsgTransfer: {time: 0},
dialogSseList: [],
dialogDroupWordChain: {},