mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
perf: 优化草稿消息
This commit is contained in:
parent
82afb5b150
commit
4061ae4275
@ -285,7 +285,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {mapState} from "vuex";
|
||||
import {mapGetters, mapState} from "vuex";
|
||||
import Quill from 'quill-hi';
|
||||
import "quill-mention-hi";
|
||||
import ChatEmoji from "./emoji";
|
||||
@ -548,6 +548,8 @@ export default {
|
||||
'isModKey',
|
||||
]),
|
||||
|
||||
...mapGetters(['getDraft']),
|
||||
|
||||
isEnterSend({cacheKeyboard}) {
|
||||
if (this.$isEEUiApp) {
|
||||
return cacheKeyboard.send_button_app === 'enter';
|
||||
@ -704,6 +706,10 @@ export default {
|
||||
}
|
||||
return style
|
||||
},
|
||||
|
||||
inputDraft() {
|
||||
return this.getDraft(this.dialogId)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// Watch content change
|
||||
@ -717,7 +723,10 @@ export default {
|
||||
}
|
||||
}
|
||||
if (!this.simpleMode) {
|
||||
this.$store.dispatch("saveDialogDraft", {id: this.dialogId, extra_draft_content: val})
|
||||
this.$store.dispatch("saveDraft", {
|
||||
dialogId: this.dialogId,
|
||||
content: val
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@ -744,7 +753,7 @@ export default {
|
||||
this.loadInputDraft()
|
||||
},
|
||||
|
||||
'dialogData.extra_draft_content'() {
|
||||
inputDraft() {
|
||||
if (this.isFocus) {
|
||||
return
|
||||
}
|
||||
@ -1208,13 +1217,12 @@ export default {
|
||||
},
|
||||
|
||||
loadInputDraft() {
|
||||
const {extra_draft_content} = this.dialogData;
|
||||
if (this.simpleMode || !extra_draft_content) {
|
||||
if (this.simpleMode || !this.inputDraft) {
|
||||
this.$emit('input', '')
|
||||
return
|
||||
}
|
||||
this.pasteClean = false
|
||||
this.$emit('input', extra_draft_content)
|
||||
this.$emit('input', this.inputDraft)
|
||||
this.$nextTick(_ => this.pasteClean = true)
|
||||
},
|
||||
|
||||
|
||||
@ -1688,9 +1688,9 @@ export default {
|
||||
if (!this.msgText) {
|
||||
return;
|
||||
}
|
||||
this.$store.dispatch("saveDialogDraft", {
|
||||
id: this.taskDetail.dialog_id,
|
||||
extra_draft_content: this.msgText
|
||||
this.$store.dispatch("saveDraft", {
|
||||
dialogId: this.taskDetail.dialog_id,
|
||||
content: this.msgText
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@ -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.extra_draft_has && dialog.id != dialogId">
|
||||
<template v-if="dialog.id != dialogId && tagDraft(dialog.id)">
|
||||
<div class="last-draft">[{{$L('草稿')}}]</div>
|
||||
<div class="last-text"><span>{{formatDraft(dialog.extra_draft_content)}}</span></div>
|
||||
<div class="last-text"><span>{{formatDraft(getDraft(dialog.id))}}</span></div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-if="dialog.type=='group' && dialog.last_msg && dialog.last_msg.userid">
|
||||
@ -260,7 +260,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {mapState} from "vuex";
|
||||
import {mapGetters, mapState} from "vuex";
|
||||
import DialogWrapper from "./components/DialogWrapper";
|
||||
import longpress from "../../directives/longpress";
|
||||
import emitter from "../../store/events";
|
||||
@ -363,6 +363,8 @@ export default {
|
||||
'taskColorList'
|
||||
]),
|
||||
|
||||
...mapGetters(['getDraft', 'tagDraft']),
|
||||
|
||||
routeName() {
|
||||
return this.$route.name
|
||||
},
|
||||
@ -738,8 +740,9 @@ export default {
|
||||
return $A.sortFloat(b.todo_num, a.todo_num);
|
||||
}
|
||||
// 根据草稿排序
|
||||
if (a.extra_draft_has || b.extra_draft_has) {
|
||||
return $A.sortFloat(b.extra_draft_has, a.extra_draft_has);
|
||||
const drafts = [this.tagDraft(a.id) ? 1 : 0, this.tagDraft(b.id) ? 1 : 0];
|
||||
if (drafts[0] || drafts[1]) {
|
||||
return $A.sortFloat(drafts[1], drafts[0]);
|
||||
}
|
||||
// 根据最后会话时间排序
|
||||
return $A.sortDay(b.last_at, a.last_at);
|
||||
|
||||
46
resources/assets/js/store/actions.js
vendored
46
resources/assets/js/store/actions.js
vendored
@ -1,4 +1,5 @@
|
||||
import * as openpgp from 'openpgp_hi/lightweight';
|
||||
import {debounce} from "lodash";
|
||||
import {initLanguage, languageList, languageName} from "../language";
|
||||
import {$callData, $urlSafe, SSEClient} from './utils'
|
||||
import emitter from "./events";
|
||||
@ -973,7 +974,8 @@ export default {
|
||||
'fileLists',
|
||||
'callAt',
|
||||
'cacheEmojis',
|
||||
'cacheDialogs'
|
||||
'cacheDialogs',
|
||||
'cacheDrafts',
|
||||
],
|
||||
json: [
|
||||
'userInfo'
|
||||
@ -996,7 +998,6 @@ export default {
|
||||
state.cacheDialogs = state.cacheDialogs.map(item => ({
|
||||
...item,
|
||||
loading: false,
|
||||
extra_draft_has: item.extra_draft_content ? 1 : 0
|
||||
}));
|
||||
|
||||
// TranslationLanguage检查
|
||||
@ -1027,11 +1028,11 @@ export default {
|
||||
|
||||
/**
|
||||
* Electron 页面卸载触发
|
||||
* @param dispatch
|
||||
* @param commit
|
||||
*/
|
||||
onBeforeUnload({dispatch}) {
|
||||
onBeforeUnload({commit}) {
|
||||
if ($A.isSubElectron && $A.isJson(window.__dialogDraft)) {
|
||||
dispatch("saveDialog", window.__dialogDraft)
|
||||
commit('SET_DRAFT', window.__dialogDraft)
|
||||
window.__dialogDraft = null;
|
||||
}
|
||||
},
|
||||
@ -3073,20 +3074,19 @@ export default {
|
||||
/**
|
||||
* 关闭对话
|
||||
* @param state
|
||||
* @param commit
|
||||
* @param dispatch
|
||||
* @param dialog_id
|
||||
*/
|
||||
closeDialog({state, dispatch}, dialog_id) {
|
||||
closeDialog({state, commit, dispatch}, dialog_id) {
|
||||
if (!/^\d+$/.test(dialog_id)) {
|
||||
return
|
||||
}
|
||||
$A.execMainDispatch("closeDialog", dialog_id)
|
||||
//
|
||||
// 更新草稿状态
|
||||
const dialog = state.cacheDialogs.find(item => item.id == dialog_id);
|
||||
if (dialog) {
|
||||
dialog.extra_draft_has = dialog.extra_draft_content ? 1 : 0
|
||||
}
|
||||
|
||||
// 更新草稿标签
|
||||
commit('TAG_DRAFT', dialog_id)
|
||||
|
||||
// 关闭会话后删除会话超限消息
|
||||
const msgs = state.dialogMsgs.filter(item => item.dialog_id == dialog_id)
|
||||
if (msgs.length > state.dialogMsgKeep) {
|
||||
@ -3176,24 +3176,17 @@ export default {
|
||||
},
|
||||
|
||||
/**
|
||||
* 保存聊天草稿
|
||||
* @param state
|
||||
* @param dispatch
|
||||
* @param data {id, extra_draft_content}
|
||||
* 保存草稿
|
||||
* @param commit
|
||||
* @param dialogId
|
||||
* @param content
|
||||
*/
|
||||
saveDialogDraft({state, dispatch}, data) {
|
||||
data.extra_draft_content = $A.filterInvalidLine(data.extra_draft_content)
|
||||
saveDraft({commit}, {dialogId, content}) {
|
||||
if ($A.isSubElectron) {
|
||||
window.__dialogDraft = data
|
||||
window.__dialogDraft = {dialogId, content}
|
||||
return
|
||||
}
|
||||
state.dialogDraftTimer[data.id] && clearTimeout(state.dialogDraftTimer[data.id])
|
||||
state.dialogDraftTimer[data.id] = setTimeout(_ => {
|
||||
if (state.dialogId != data.id) {
|
||||
data.extra_draft_has = data.extra_draft_content ? 1 : 0
|
||||
}
|
||||
dispatch("saveDialog", data)
|
||||
}, data.extra_draft_content ? 600 : 0)
|
||||
commit('SET_DRAFT', {dialogId, content})
|
||||
},
|
||||
|
||||
/** *****************************************************************************************/
|
||||
@ -4428,6 +4421,5 @@ export default {
|
||||
},10)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
20
resources/assets/js/store/getters.js
vendored
20
resources/assets/js/store/getters.js
vendored
@ -238,4 +238,24 @@ export default {
|
||||
return timeA - timeB;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取草稿
|
||||
* @param state
|
||||
* @returns {function(*): *|string}
|
||||
*/
|
||||
getDraft: (state) => (dialogId) => {
|
||||
const draft = state.cacheDrafts.find(item => item.dialogId === dialogId)
|
||||
return draft ? draft.content : ''
|
||||
},
|
||||
|
||||
/**
|
||||
* 是否显示草稿标签
|
||||
* @param state
|
||||
* @returns {function(*): boolean}
|
||||
*/
|
||||
tagDraft: (state) => (dialogId) => {
|
||||
const draft = state.cacheDrafts.find(item => item.dialogId === dialogId)
|
||||
return !!draft?.tag
|
||||
},
|
||||
}
|
||||
|
||||
30
resources/assets/js/store/mutations.js
vendored
30
resources/assets/js/store/mutations.js
vendored
@ -1,3 +1,33 @@
|
||||
export default {
|
||||
// 设置草稿
|
||||
SET_DRAFT(state, {dialogId, content}) {
|
||||
const index = state.cacheDrafts.findIndex(item => item.dialogId === dialogId)
|
||||
const item = {
|
||||
dialogId,
|
||||
content: $A.filterInvalidLine(content),
|
||||
time: new Date().getTime()
|
||||
}
|
||||
|
||||
if (index !== -1) {
|
||||
// 更新已存在的草稿
|
||||
item.tag = state.cacheDrafts[index].tag
|
||||
state.cacheDrafts.splice(index, 1, item)
|
||||
} else {
|
||||
// 添加新草稿
|
||||
item.tag = state.dialogId != dialogId
|
||||
state.cacheDrafts.push(item)
|
||||
}
|
||||
|
||||
// 保存到 IndexedDB
|
||||
$A.IDBSave("cacheDrafts", state.cacheDrafts)
|
||||
},
|
||||
|
||||
// 显示草稿标签
|
||||
TAG_DRAFT(state, dialogId) {
|
||||
const index = state.cacheDrafts.findIndex(item => item.dialogId === dialogId)
|
||||
if (index !== -1) {
|
||||
state.cacheDrafts[index].tag = !!state.cacheDrafts[index].content
|
||||
$A.IDBSave("cacheDrafts", state.cacheDrafts)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
4
resources/assets/js/store/state.js
vendored
4
resources/assets/js/store/state.js
vendored
@ -78,6 +78,9 @@ export default {
|
||||
// Dialog
|
||||
cacheDialogs: [],
|
||||
|
||||
// Draft
|
||||
cacheDrafts: [],
|
||||
|
||||
// Project
|
||||
cacheProjects: [],
|
||||
cacheColumns: [],
|
||||
@ -123,7 +126,6 @@ export default {
|
||||
dialogTodos: [],
|
||||
dialogMsgTops: [],
|
||||
dialogHistory: [],
|
||||
dialogDraftTimer: {},
|
||||
dialogMsgTransfer: {time: 0},
|
||||
dialogSseList: [],
|
||||
dialogDroupWordChain: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user