From 4ef5deac69c46ec9216f572dc066a035132f4ee5 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 7 Dec 2022 19:50:43 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E4=BF=9D=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/manage/components/DialogWrapper.vue | 6 ++-- resources/assets/js/store/actions.js | 33 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index ec6a62972..ccb681caf 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -560,6 +560,7 @@ export default { beforeDestroy() { this.$store.dispatch('forgetInDialog', this._uid) + this.$store.dispatch('closeDialog', this.dialogId) }, computed: { @@ -788,7 +789,7 @@ export default { watch: { dialogId: { - handler(dialog_id) { + handler(dialog_id, old_id) { if (dialog_id) { this.msgNew = 0 this.msgType = '' @@ -816,6 +817,7 @@ export default { this.inputFocus() } } + this.$store.dispatch('closeDialog', old_id) }, immediate: true }, @@ -1718,7 +1720,7 @@ export default { handleBack() { const {name, params} = this.$store.state.routeHistoryLast; - if (name === this.$route.name && /\d+/.test(params.dialogId)) { + if (name === this.$route.name && /^\d+$/.test(params.dialogId)) { this.goForward({name: this.$route.name}); } else { this.goBack(); diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index efa3b8f33..bef62bd47 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -2107,8 +2107,8 @@ export default { search_msg_id = dialog_id.search_msg_id; dialog_id = dialog_id.dialog_id; } - state.dialogSearchMsgId = /\d+/.test(search_msg_id) ? search_msg_id : 0; - state.dialogId = /\d+/.test(dialog_id) ? dialog_id : 0; + state.dialogSearchMsgId = /^\d+$/.test(search_msg_id) ? search_msg_id : 0; + state.dialogId = /^\d+$/.test(dialog_id) ? dialog_id : 0; }, /** @@ -2174,9 +2174,9 @@ export default { } else { state.dialogIns.push(data); } - // 会话消息总数量大于500时只保留最近打开的10个会话 - const msg_max = 500 - const retain_num = 10 + // 会话消息总数量大于1000时只保留最近打开的20个会话 + const msg_max = 1000 + const retain_num = 20 state.dialogHistory = state.dialogHistory.filter(id => id != data.dialog_id) state.dialogHistory.push(data.dialog_id) if (state.dialogMsgs.length > msg_max && state.dialogHistory.length > retain_num) { @@ -2212,6 +2212,29 @@ export default { } }, + /** + * 关闭对话 + * @param state + * @param dispatch + * @param dialog_id + */ + closeDialog({state, dispatch}, dialog_id) { + $A.execMainDispatch("closeDialog", dialog_id) + // + if (!/^\d+$/.test(dialog_id)) { + return + } + // 关闭会话后只保留会话最后50条数据 + const retain = 5 + const msgs = state.dialogMsgs.filter(item => item.dialog_id == dialog_id) + if (msgs.length > retain) { + const delIds = msgs.sort((a, b) => { + return b.id - a.id + }).splice(retain).map(item => item.id) + state.dialogMsgs = state.dialogMsgs.filter(item => !delIds.includes(item.id)) + } + }, + /** * 保存待办数据 * @param state