perf: 优化未读消息提示

This commit is contained in:
kuaifan 2023-12-28 20:48:23 +08:00
parent fbd662e400
commit 54117fe51a
4 changed files with 32 additions and 20 deletions

View File

@ -137,7 +137,7 @@
</div> </div>
<!--跳转提示--> <!--跳转提示-->
<div v-if="listPreparedStatus && positionMsg" class="dialog-position" :class="{'down': tagShow}"> <div v-if="positionShow && 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>
@ -731,6 +731,7 @@ export default {
unreadMsgId: 0, // id unreadMsgId: 0, // id
positionLoad: 0, // positionLoad: 0, //
positionShow: false, //
firstMsgLength: 0, // firstMsgLength: 0, //
isFirstShowTag: false, // isFirstShowTag: false, //
msgPreparedStatus: false, // msgPreparedStatus: false, //
@ -777,6 +778,7 @@ export default {
'fileLinks', 'fileLinks',
'cacheEmojis', 'cacheEmojis',
'readReqNum',
'keyboardType', 'keyboardType',
'keyboardHeight', 'keyboardHeight',
'safeAreaBottom' 'safeAreaBottom'
@ -1042,9 +1044,9 @@ export default {
return null return null
}, },
positionMsg() { positionMsg({msgNew, dialogData, allMsgs}) {
const {mention, unread, position_msgs} = this.dialogData const {mention, unread, position_msgs} = dialogData
if (!position_msgs || position_msgs.length === 0 || unread === 0 || this.allMsgs.length === 0) { if (!position_msgs || position_msgs.length === 0 || (unread - msgNew) <= 0 || allMsgs.length === 0) {
return null return null
} }
const item = $A.cloneJSON(position_msgs.find(item => { const item = $A.cloneJSON(position_msgs.find(item => {
@ -1059,8 +1061,8 @@ export default {
return item return item
}, },
operateEmojis() { operateEmojis({cacheEmojis}) {
const list = this.cacheEmojis.slice(0, 3) const list = cacheEmojis.slice(0, 3)
Object.values(['👌', '👍', '😂', '🎉', '❤️', '🥳️', '🥰', '😥', '😭']).some(item => { Object.values(['👌', '👍', '😂', '🎉', '❤️', '🥳️', '🥰', '😥', '😭']).some(item => {
if (!list.includes(item)) { if (!list.includes(item)) {
list.push(item) list.push(item)
@ -1069,15 +1071,15 @@ export default {
return list return list
}, },
maxSize() { maxSize({systemConfig}) {
if(this.systemConfig?.file_upload_limit){ if(systemConfig?.file_upload_limit){
return this.systemConfig.file_upload_limit * 1024 return systemConfig.file_upload_limit * 1024
} }
return 1024000 return 1024000
}, },
readEnabled() { readEnabled({msgPreparedStatus, listPreparedStatus}) {
return this.msgPreparedStatus && this.listPreparedStatus return msgPreparedStatus && listPreparedStatus
}, },
}, },
@ -1089,6 +1091,7 @@ export default {
this.msgType = '' this.msgType = ''
this.searchShow = false this.searchShow = false
this.unreadMsgId = 0 this.unreadMsgId = 0
this.positionShow = false
this.firstMsgLength = this.allMsgList.length || 1 this.firstMsgLength = this.allMsgList.length || 1
this.listPreparedStatus = false this.listPreparedStatus = false
this.scrollToBottomAndRefresh = false this.scrollToBottomAndRefresh = false
@ -1339,6 +1342,10 @@ export default {
} }
} }
}, },
readReqNum() {
this.positionShow = true
},
}, },
methods: { methods: {

View File

@ -2992,15 +2992,15 @@ export default {
if (data.userid == state.userId) return; if (data.userid == state.userId) return;
if (data.read_at) return; if (data.read_at) return;
data.read_at = $A.formatDate(); data.read_at = $A.formatDate();
state.wsReadWaitData[data.id] = data.id; state.readWaitData[data.id] = data.id;
} }
clearTimeout(state.wsReadTimeout); clearTimeout(state.readTimeout);
state.wsReadTimeout = setTimeout(_ => { state.readTimeout = setTimeout(_ => {
if (state.userId === 0) { if (state.userId === 0) {
return; return;
} }
const ids = Object.values(state.wsReadWaitData); const ids = Object.values(state.readWaitData);
state.wsReadWaitData = {}; state.readWaitData = {};
if (ids.length === 0) { if (ids.length === 0) {
return return
} }
@ -3014,8 +3014,10 @@ export default {
dispatch("saveDialog", data) dispatch("saveDialog", data)
}).catch(_ => { }).catch(_ => {
ids.some(id => { ids.some(id => {
state.wsReadWaitData[id] = id; state.readWaitData[id] = id;
}) })
}).finally(_ => {
state.readReqNum++
}); });
}, 50); }, 50);
}, },

View File

@ -98,8 +98,6 @@ export default {
wsRandom: 0, wsRandom: 0,
wsOpenNum: 0, wsOpenNum: 0,
wsListener: {}, wsListener: {},
wsReadTimeout: null,
wsReadWaitData: {},
// 会员信息 // 会员信息
userInfo: {}, userInfo: {},
@ -125,6 +123,11 @@ export default {
// 搜索关键词(主要用于移动端判断滑动返回) // 搜索关键词(主要用于移动端判断滑动返回)
messengerSearchKey: {dialog: '', contacts: ''}, messengerSearchKey: {dialog: '', contacts: ''},
// 阅读消息
readReqNum: 0,
readTimeout: null,
readWaitData: {},
// 文件 // 文件
fileLists: [], fileLists: [],
fileLinks: [], fileLinks: [],

View File

@ -1449,7 +1449,7 @@
opacity: 0; opacity: 0;
transform: translateX(100%); transform: translateX(100%);
animation: position-in-animation 200ms ease-out forwards; animation: position-in-animation 200ms ease-out forwards;
animation-delay: 600ms; animation-delay: 100ms;
.position-label { .position-label {
display: flex; display: flex;