perf: 优化未读消息机制

This commit is contained in:
kuaifan 2023-12-15 00:14:48 +08:00
parent e5c622cb89
commit f8f5bc476b
2 changed files with 36 additions and 25 deletions

View File

@ -104,10 +104,10 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
}, msgReady: {
type: Boolean,
mounted() { default: false
this.checkWatch() },
}, },
computed: { computed: {
@ -121,7 +121,7 @@ export default {
return this.simpleView || this.msgId === this.source.id return this.simpleView || this.msgId === this.source.id
}, },
isNoWatch() { isNoRead() {
return this.isRightMsg || this.source.read_at return this.isRightMsg || this.source.read_at
}, },
@ -148,32 +148,25 @@ export default {
}, },
watch: { watch: {
source() { msgReady() {
this.msgRead(); this.msgRead();
}, },
windowActive(active) { windowActive() {
if (!active) {
return
}
this.msgRead(); this.msgRead();
} },
scrollIng() {
this.msgRead();
},
}, },
methods: { methods: {
checkWatch() {
if (this.isNoWatch) {
return
}
const watchr = this.$watch("scrollIng", _ => {
if (this.isNoWatch) {
watchr()
return
}
this.msgRead()
})
},
msgRead() { msgRead() {
if (this.isNoRead) {
return;
}
if (!this.msgReady) {
return;
}
if (!this.windowActive) { if (!this.windowActive) {
return; return;
} }

View File

@ -155,7 +155,7 @@
:data-component="msgItem" :data-component="msgItem"
:item-class-add="itemClassAdd" :item-class-add="itemClassAdd"
:extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng}" :extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng, msgReady}"
:estimate-size="dialogData.type=='group' ? 105 : 77" :estimate-size="dialogData.type=='group' ? 105 : 77"
:keeps="25" :keeps="25"
:disabled="scrollDisabled" :disabled="scrollDisabled"
@ -658,6 +658,7 @@ export default {
approvaUserStatus: '', approvaUserStatus: '',
positionLoad: 0, // positionLoad: 0, //
msgReady: false, //
unreadMsgId: 0, // id unreadMsgId: 0, // id
toBottomReGetMsg: false, // toBottomReGetMsg: false, //
} }
@ -997,6 +998,7 @@ export default {
this.msgNew = 0 this.msgNew = 0
this.msgType = '' this.msgType = ''
this.searchShow = false this.searchShow = false
this.msgReady = false
this.unreadMsgId = 0 this.unreadMsgId = 0
this.toBottomReGetMsg = false this.toBottomReGetMsg = false
// //
@ -1010,6 +1012,7 @@ export default {
msg_type: this.msgType, msg_type: this.msgType,
}).then(_ => { }).then(_ => {
this.openId = dialog_id; this.openId = dialog_id;
this.onMsgReady()
setTimeout(this.onSearchMsgId, 100) setTimeout(this.onSearchMsgId, 100)
}).catch(_ => {}); }).catch(_ => {});
// //
@ -1462,6 +1465,21 @@ export default {
return true return true
}, },
onMsgReady() {
let count = 0;
let offsetA = this.scrollInfo().offset
const func = () => {
const offsetB = this.scrollInfo().offset
if (++count > 10 || offsetA == offsetB) {
this.msgReady = true
return
}
offsetA = offsetB
setTimeout(func, 200);
}
setTimeout(func, 200);
},
onSearchMsgId() { onSearchMsgId() {
if (this.dialogSearchMsgId > 0 && this.openId === this.dialogId) { if (this.dialogSearchMsgId > 0 && this.openId === this.dialogId) {
this.onPositionId(this.dialogSearchMsgId) this.onPositionId(this.dialogSearchMsgId)