perf: 优化发送消息时闪现2条一样的情况

This commit is contained in:
kuaifan 2023-12-21 14:35:57 +08:00
parent ce83bef0ed
commit a185ab2973

View File

@ -1208,7 +1208,7 @@ export default {
}, },
allMsgList(newList, oldList) { allMsgList(newList, oldList) {
if(JSON.stringify(newList) == JSON.stringify(oldList)){ if (JSON.stringify(newList) == JSON.stringify(oldList)) {
return; return;
} }
const {tail} = this.scrollInfo(); const {tail} = this.scrollInfo();
@ -1393,8 +1393,7 @@ export default {
}, },
method: 'post', method: 'post',
}).then(({data}) => { }).then(({data}) => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempMsg.id) this.sendSuccess(data, tempMsg.id)
this.sendSuccess(data)
}).catch(error => { }).catch(error => {
this.$set(tempMsg, 'error', true) this.$set(tempMsg, 'error', true)
this.$set(tempMsg, 'errorData', {type: 'text', mType: type, content: error.msg, msg: textBody}) this.$set(tempMsg, 'errorData', {type: 'text', mType: type, content: error.msg, msg: textBody})
@ -1433,8 +1432,7 @@ export default {
}), }),
method: 'post', method: 'post',
}).then(({data}) => { }).then(({data}) => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempMsg.id) this.sendSuccess(data, tempMsg.id);
this.sendSuccess(data);
}).catch(error => { }).catch(error => {
this.$set(tempMsg, 'error', true) this.$set(tempMsg, 'error', true)
this.$set(tempMsg, 'errorData', {type: 'record', mType: 'record', content: error.msg, msg}) this.$set(tempMsg, 'errorData', {type: 'record', mType: 'record', content: error.msg, msg})
@ -1834,21 +1832,31 @@ export default {
break; break;
case 'error': case 'error':
this.tempMsgs = this.tempMsgs.filter(({id}) => id != file.tempId) this.forgetTempMsg(file.tempId)
break; break;
case 'success': case 'success':
this.tempMsgs = this.tempMsgs.filter(({id}) => id != file.tempId) this.sendSuccess(file.data, file.tempId)
this.sendSuccess(file.data)
break; break;
} }
}, },
sendSuccess(data) { sendSuccess(data, tempId = 0) {
if ($A.isArray(data)) { if ($A.isArray(data)) {
data.some(this.sendSuccess) data.some(item => {
this.sendSuccess(item, tempId)
})
return; return;
} }
if (tempId > 0) {
const index = this.tempMsgs.findIndex(({id}) => id == tempId)
if (index > -1) {
this.tempMsgs.splice(index, 1, data)
}
setTimeout(_ => {
this.forgetTempMsg(tempId)
}, 1000)
}
this.$store.dispatch("saveDialogMsg", data); this.$store.dispatch("saveDialogMsg", data);
if (!this.quoteUpdate) { if (!this.quoteUpdate) {
this.$store.dispatch("increaseTaskMsgNum", data); this.$store.dispatch("increaseTaskMsgNum", data);
@ -1859,6 +1867,10 @@ export default {
this.onActive(); this.onActive();
}, },
forgetTempMsg(tempId) {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != tempId)
},
setQuote(id, type) { setQuote(id, type) {
this.$refs.input?.setQuote(id, type) this.$refs.input?.setQuote(id, type)
}, },
@ -2888,19 +2900,19 @@ export default {
content, content,
cancelText: '取消发送', cancelText: '取消发送',
onCancel: _ => { onCancel: _ => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id) this.forgetTempMsg(data.id)
} }
} }
if (type === 'text') { if (type === 'text') {
config.okText = '重新发送' config.okText = '重新发送'
config.onOk = () => { config.onOk = () => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id) this.forgetTempMsg(data.id)
this.sendMsg(msg, mType) this.sendMsg(msg, mType)
} }
} else if (type === 'record') { } else if (type === 'record') {
config.okText = '重新发送' config.okText = '重新发送'
config.onOk = () => { config.onOk = () => {
this.tempMsgs = this.tempMsgs.filter(({id}) => id != data.id) this.forgetTempMsg(data.id)
this.sendRecord(msg) this.sendRecord(msg)
} }
} else { } else {