perf: 优化消息阅读规则

This commit is contained in:
kuaifan 2023-12-19 10:53:31 +08:00
parent 3f9cdfd887
commit c21da4292b
2 changed files with 27 additions and 19 deletions

View File

@ -104,7 +104,7 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
msgReady: { readEnabled: {
type: Boolean, type: Boolean,
default: false default: false
}, },
@ -148,7 +148,7 @@ export default {
}, },
watch: { watch: {
msgReady() { readEnabled() {
this.msgRead(); this.msgRead();
}, },
windowActive() { windowActive() {
@ -164,7 +164,7 @@ export default {
if (this.isNoRead) { if (this.isNoRead) {
return; return;
} }
if (!this.msgReady) { if (!this.readEnabled) {
return; return;
} }
if (!this.windowActive) { if (!this.windowActive) {

View File

@ -137,7 +137,7 @@
</div> </div>
<!--跳转提示--> <!--跳转提示-->
<div v-if="positionMsg" class="dialog-position" :class="{'down': tagShow}"> <div v-if="readEnabled && positionMsg" class="dialog-position" :class="{'down': tagShow}">
<div class="position-label" @click="onPositionMark"> <div class="position-label" @click="onPositionMark">
<Icon v-if="positionLoad > 0" type="ios-loading" class="icon-loading"></Icon> <Icon v-if="positionLoad > 0" type="ios-loading" class="icon-loading"></Icon>
<i v-else class="taskfont">&#xe624;</i> <i v-else class="taskfont">&#xe624;</i>
@ -156,7 +156,7 @@
:data-component="msgItem" :data-component="msgItem"
:item-class-add="itemClassAdd" :item-class-add="itemClassAdd"
:extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng, msgReady}" :extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng, readEnabled}"
:estimate-size="dialogData.type=='group' ? 105 : 77" :estimate-size="dialogData.type=='group' ? 105 : 77"
:keeps="25" :keeps="25"
:disabled="scrollDisabled" :disabled="scrollDisabled"
@ -696,11 +696,12 @@ export default {
approveDetailsShow: false, approveDetailsShow: false,
approvaUserStatus: '', approvaUserStatus: '',
positionLoad: 0, // unreadMsgId: 0, // id
msgReady: false, // positionLoad: 0, //
unreadMsgId: 0, // id msgPreparedStatus: false, //
toBottomReGetMsg: false, // listPreparedStatus: false, //
selectionRange: false, // selectedTextStatus: false, //
scrollToBottomAndRefresh: false, //
} }
}, },
@ -1034,7 +1035,11 @@ export default {
return this.systemConfig.file_upload_limit * 1024 return this.systemConfig.file_upload_limit * 1024
} }
return 1024000 return 1024000
} },
readEnabled() {
return this.msgPreparedStatus && this.listPreparedStatus
},
}, },
watch: { watch: {
@ -1045,7 +1050,8 @@ export default {
this.msgType = '' this.msgType = ''
this.searchShow = false this.searchShow = false
this.unreadMsgId = 0 this.unreadMsgId = 0
this.toBottomReGetMsg = false this.listPreparedStatus = false
this.scrollToBottomAndRefresh = false
// //
if (this.allMsgList.length > 0) { if (this.allMsgList.length > 0) {
this.allMsgs = this.allMsgList this.allMsgs = this.allMsgList
@ -1058,7 +1064,9 @@ export default {
}).then(_ => { }).then(_ => {
this.openId = dialog_id; this.openId = dialog_id;
setTimeout(this.onSearchMsgId, 100) setTimeout(this.onSearchMsgId, 100)
}).catch(_ => {}); }).catch(_ => {}).finally(_ => {
this.listPreparedStatus = true
});
// //
this.$store.dispatch('saveInDialog', { this.$store.dispatch('saveInDialog', {
uid: this._uid, uid: this._uid,
@ -1167,7 +1175,7 @@ export default {
const lastMsg = this.allMsgs[this.allMsgs.length - 1] const lastMsg = this.allMsgs[this.allMsgs.length - 1]
const lastEl = $A(this.$refs.scroller.$el).find(`[data-id="${lastMsg.id}"]`) const lastEl = $A(this.$refs.scroller.$el).find(`[data-id="${lastMsg.id}"]`)
if (lastEl.length === 0) { if (lastEl.length === 0) {
this.toBottomReGetMsg = true this.scrollToBottomAndRefresh = true
return; return;
} }
// //
@ -1474,7 +1482,7 @@ export default {
onSelectionchange() { onSelectionchange() {
const selectionType = window.getSelection().type; const selectionType = window.getSelection().type;
this.selectionRange = selectionType === "Range" this.selectedTextStatus = selectionType === "Range"
}, },
getTempId() { getTempId() {
@ -1714,7 +1722,7 @@ export default {
onTouchStart(e) { onTouchStart(e) {
this.wrapperStart = null; this.wrapperStart = null;
if (this.selectionRange) { if (this.selectedTextStatus) {
this.wrapperStart = window.scrollY this.wrapperStart = window.scrollY
return return
} }
@ -2013,7 +2021,7 @@ export default {
}, },
onReGetMsg() { onReGetMsg() {
this.toBottomReGetMsg = false this.scrollToBottomAndRefresh = false
this.getMsgs({ this.getMsgs({
dialog_id: this.dialogId, dialog_id: this.dialogId,
msg_id: this.msgId, msg_id: this.msgId,
@ -2306,7 +2314,7 @@ export default {
}, },
onActivity(activity) { onActivity(activity) {
this.msgReady = !activity this.msgPreparedStatus = !activity
}, },
onScroll(event) { onScroll(event) {
@ -2319,7 +2327,7 @@ export default {
this.scrollTail = tail; this.scrollTail = tail;
if (this.scrollTail <= 55) { if (this.scrollTail <= 55) {
this.msgNew = 0; this.msgNew = 0;
this.toBottomReGetMsg && this.onReGetMsg() this.scrollToBottomAndRefresh && this.onReGetMsg()
} }
// //
this.scrollAction = event.target.scrollTop; this.scrollAction = event.target.scrollTop;