From 5b02d8008f40d4d87864e79998698895d5ebc4ea Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 12 Dec 2024 13:41:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B5=81=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/manage/components/DialogWrapper.vue | 62 +++++++++---------- resources/assets/js/store/actions.js | 5 +- resources/assets/js/store/mutations.js | 4 +- resources/assets/js/store/state.js | 1 + 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 86cd7e127..43ff7c843 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -873,7 +873,6 @@ export default { mounted() { this.subMsgListener() - this.msgSubscribe = Store.subscribe('dialogMsgChange', this.onMsgChange); }, beforeDestroy() { @@ -885,10 +884,6 @@ export default { this.$store.dispatch('closeDialog', this.dialogId) } // - if (this.msgSubscribe) { - this.msgSubscribe.unsubscribe(); - this.msgSubscribe = null; - } this.observers.forEach(({observer}) => observer.disconnect()) this.observers = [] // @@ -910,6 +905,7 @@ export default { 'dialogMsgTransfer', 'dialogMsgKeep', 'dialogIns', + 'dialogMsgStream', 'cacheDialogs', 'wsOpenNum', 'touchBackInProgress', @@ -1489,6 +1485,34 @@ export default { } document.getSelection().removeAllRanges(); }, + + dialogMsgStream(data) { + const item = this.allMsgs.find(({type, id}) => type == "text" && id == data.id) + if (!item) { + return + } + if (typeof this.msgChangeCache[data.id] === "undefined") { + this.msgChangeCache[data.id] = [] + this.msgChangeCache[`${data.id}_load`] = false + } + switch (data.type) { + case 'append': + data.text && this.msgChangeCache[data.id].push(...`${data.text}`.split("").map(text => { + return { + type: 'append', + text + } + })) + break; + case 'replace': + this.msgChangeCache[data.id] = [{ + type: 'replace', + text: data.text + }] + break; + } + this.onMsgOutput(data.id, item.msg) + } }, methods: { @@ -1863,34 +1887,6 @@ export default { } }, - /** - * 消息变化处理 - * @param data - */ - onMsgChange(data) { - const item = this.allMsgs.find(({type, id}) => type == "text" && id == data.id) - if (item) { - if (typeof this.msgChangeCache[data.id] === "undefined") { - this.msgChangeCache[data.id] = [] - this.msgChangeCache[`${data.id}_load`] = false - } - if (data.type === 'append') { - this.msgChangeCache[data.id].push(...`${data.text}`.split("").map(text => { - return { - type: 'append', - text - } - })) - } else if (data.type === 'replace') { - this.msgChangeCache[data.id] = [{ - type: 'replace', - text: data.text - }] - } - this.onMsgOutput(data.id, item.msg) - } - }, - /** * 追加或替换消息 * @param id diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index d2158e7bd..40218fd8a 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -3436,9 +3436,10 @@ export default { * 消息流 * @param state * @param dispatch + * @param commit * @param streamUrl */ - streamDialogMsg({state, dispatch}, streamUrl) { + streamDialogMsg({state, dispatch, commit}, streamUrl) { if (!/^https?:\/\//i.test(streamUrl)) { streamUrl = $A.mainUrl(streamUrl.substring(1)) } @@ -3451,7 +3452,7 @@ export default { case 'append': case 'replace': const data = $A.jsonParse(e.data); - Store.set('dialogMsgChange', { + commit('setDialogMsgStream', { type, id: e.lastEventId, text: data.content diff --git a/resources/assets/js/store/mutations.js b/resources/assets/js/store/mutations.js index 03048022a..9b47c2196 100644 --- a/resources/assets/js/store/mutations.js +++ b/resources/assets/js/store/mutations.js @@ -1,3 +1,5 @@ export default { - + setDialogMsgStream(state, data) { + state.dialogMsgStream = data; + } } diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index f2af66a71..1d6f5fb95 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -121,6 +121,7 @@ export default { dialogHistory: [], dialogDraftTimer: {}, dialogMsgTransfer: {time: 0}, + dialogMsgStream: {}, dialogSseList: [], dialogDroupWordChain: {}, dialogGroupVote: {},