perf: 优化消息定位

This commit is contained in:
kuaifan 2025-03-10 23:01:31 +08:00
parent 9d8af2eaab
commit 1c2798cbf4

View File

@ -882,7 +882,8 @@ export default {
topPosLoad: 0, // topPosLoad: 0, //
positionLoad: 0, // positionLoad: 0, //
positionShow: false, // positionShow: false, //
preventMoreLoad: false, // preventPrevLoad: 0, // 0
preventRangeLoad: 0, // 0
preventToBottom: false, // preventToBottom: false, //
scrollToBottomRefresh: false, // scrollToBottomRefresh: false, //
androidKeyboardVisible: false, // Android androidKeyboardVisible: false, // Android
@ -2539,8 +2540,9 @@ export default {
this.msgNew = 0; this.msgNew = 0;
const scroller = this.$refs.scroller; const scroller = this.$refs.scroller;
if (scroller) { if (scroller) {
scroller.scrollToBottom(); this.preventLoad().then(_ => {
requestAnimationFrame(_ => scroller.scrollToBottom()) // scroller.scrollToBottom();
})
} }
}, },
@ -2550,8 +2552,9 @@ export default {
scroller.stopToBottom(); scroller.stopToBottom();
const element = scroller.$el.querySelector(`[data-id="${id}"]`) const element = scroller.$el.querySelector(`[data-id="${id}"]`)
if (!element?.parentNode.parentNode.classList.contains('item-enter')) { if (!element?.parentNode.parentNode.classList.contains('item-enter')) {
scroller.scrollToIndex(index, -80); this.preventLoad().then(_ => {
requestAnimationFrame(_ => scroller.scrollToIndex(index, -80)) // scroller.scrollToIndex(index, -80);
})
} }
} }
requestAnimationFrame(_ => this.msgActiveId = id) requestAnimationFrame(_ => this.msgActiveId = id)
@ -2573,6 +2576,18 @@ export default {
} }
}, },
preventLoad() {
return new Promise(resolve => {
this.preventPrevLoad++
this.preventRangeLoad++
resolve()
requestAnimationFrame(_ => {
this.preventPrevLoad--
this.preventRangeLoad--
})
})
},
scrollInfo() { scrollInfo() {
const scroller = this.$refs.scroller; const scroller = this.$refs.scroller;
if (scroller) { if (scroller) {
@ -2642,7 +2657,7 @@ export default {
}, },
onPrevPage() { onPrevPage() {
if (this.prevId === 0) { if (this.prevId === 0 || this.preventPrevLoad > 0) {
return return
} }
this.getMsgs({ this.getMsgs({
@ -3006,7 +3021,7 @@ export default {
}, },
onRange(range) { onRange(range) {
if (this.preventMoreLoad) { if (this.preventRangeLoad > 0) {
return return
} }
const key = this.scrollDirection === 'down' ? 'next_id' : 'prev_id'; const key = this.scrollDirection === 'down' ? 'next_id' : 'prev_id';
@ -3020,14 +3035,14 @@ export default {
} }
const nearMsg = this.allMsgs[i + (key === 'next_id' ? 1 : -1)] const nearMsg = this.allMsgs[i + (key === 'next_id' ? 1 : -1)]
if (nearMsg && nearMsg.id != rangeValue) { if (nearMsg && nearMsg.id != rangeValue) {
this.preventMoreLoad = true this.preventRangeLoad++
this.getMsgs({ this.getMsgs({
dialog_id: this.dialogId, dialog_id: this.dialogId,
msg_id: this.msgId, msg_id: this.msgId,
msg_type: this.msgType, msg_type: this.msgType,
[key]: rangeValue, [key]: rangeValue,
}).finally(_ => { }).finally(_ => {
this.preventMoreLoad = false this.preventRangeLoad--
}) })
} }
} }