perf: 优化数据流

This commit is contained in:
kuaifan 2024-12-16 17:04:45 +08:00
parent 207f09a4af
commit 8eb0a49ee6
4 changed files with 37 additions and 36 deletions

View File

@ -873,9 +873,11 @@ export default {
mounted() { mounted() {
this.subMsgListener() this.subMsgListener()
emitter.on('dialogMsgChange', this.onMsgChange);
}, },
beforeDestroy() { beforeDestroy() {
emitter.off('dialogMsgChange', this.onMsgChange);
this.subMsgListener(true) this.subMsgListener(true)
this.generateUnreadData(this.dialogId) this.generateUnreadData(this.dialogId)
// //
@ -905,7 +907,6 @@ export default {
'dialogMsgTransfer', 'dialogMsgTransfer',
'dialogMsgKeep', 'dialogMsgKeep',
'dialogIns', 'dialogIns',
'dialogMsgStream',
'cacheDialogs', 'cacheDialogs',
'wsOpenNum', 'wsOpenNum',
'touchBackInProgress', 'touchBackInProgress',
@ -1484,34 +1485,6 @@ export default {
return return
} }
document.getSelection().removeAllRanges(); 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)
} }
}, },
@ -1887,6 +1860,38 @@ export default {
} }
}, },
/**
* 消息变化处理
* @param data
*/
onMsgChange(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)
},
/** /**
* 追加或替换消息 * 追加或替换消息
* @param id * @param id

View File

@ -3452,10 +3452,9 @@ export default {
* 消息流 * 消息流
* @param state * @param state
* @param dispatch * @param dispatch
* @param commit
* @param streamUrl * @param streamUrl
*/ */
streamDialogMsg({state, dispatch, commit}, streamUrl) { streamDialogMsg({state, dispatch}, streamUrl) {
if (!/^https?:\/\//i.test(streamUrl)) { if (!/^https?:\/\//i.test(streamUrl)) {
streamUrl = $A.mainUrl(streamUrl.substring(1)) streamUrl = $A.mainUrl(streamUrl.substring(1))
} }
@ -3468,7 +3467,7 @@ export default {
case 'append': case 'append':
case 'replace': case 'replace':
const data = $A.jsonParse(e.data); const data = $A.jsonParse(e.data);
commit('setDialogMsgStream', { emitter.emit('dialogMsgChange', {
type, type,
id: e.lastEventId, id: e.lastEventId,
text: data.content text: data.content

View File

@ -1,5 +1,3 @@
export default { export default {
setDialogMsgStream(state, data) {
state.dialogMsgStream = data;
}
} }

View File

@ -121,7 +121,6 @@ export default {
dialogHistory: [], dialogHistory: [],
dialogDraftTimer: {}, dialogDraftTimer: {},
dialogMsgTransfer: {time: 0}, dialogMsgTransfer: {time: 0},
dialogMsgStream: {},
dialogSseList: [], dialogSseList: [],
dialogDroupWordChain: {}, dialogDroupWordChain: {},
dialogGroupVote: {}, dialogGroupVote: {},