mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-02 17:28:17 +00:00
perf: 优化数据流消息
This commit is contained in:
parent
a032c6114f
commit
5b02d8008f
@ -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
|
||||
|
||||
5
resources/assets/js/store/actions.js
vendored
5
resources/assets/js/store/actions.js
vendored
@ -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
|
||||
|
||||
4
resources/assets/js/store/mutations.js
vendored
4
resources/assets/js/store/mutations.js
vendored
@ -1,3 +1,5 @@
|
||||
export default {
|
||||
|
||||
setDialogMsgStream(state, data) {
|
||||
state.dialogMsgStream = data;
|
||||
}
|
||||
}
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -121,6 +121,7 @@ export default {
|
||||
dialogHistory: [],
|
||||
dialogDraftTimer: {},
|
||||
dialogMsgTransfer: {time: 0},
|
||||
dialogMsgStream: {},
|
||||
dialogSseList: [],
|
||||
dialogDroupWordChain: {},
|
||||
dialogGroupVote: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user