mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-01 18:38:13 +00:00
perf: 优化未读消息机制
This commit is contained in:
parent
9ca9de0d7e
commit
c0342ea6d1
@ -93,25 +93,31 @@ export default {
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
},
|
},
|
||||||
|
scrollIng: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
mounted() {
|
||||||
return {
|
this.checkWatch()
|
||||||
subscribe: null,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['userId']),
|
...mapState(['userId']),
|
||||||
|
|
||||||
isRightMsg() {
|
isRightMsg() {
|
||||||
return this.source.userid == this.userId
|
return this.source.userid == this.$store.state.userId
|
||||||
},
|
},
|
||||||
|
|
||||||
isReply() {
|
isReply() {
|
||||||
return this.simpleView || this.msgId === this.source.id
|
return this.simpleView || this.msgId === this.source.id
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isNoWatch() {
|
||||||
|
return this.isRightMsg || this.source.read_at
|
||||||
|
},
|
||||||
|
|
||||||
hidePercentage() {
|
hidePercentage() {
|
||||||
return this.simpleView || this.isMyDialog || this.isReply
|
return this.simpleView || this.isMyDialog || this.isReply
|
||||||
},
|
},
|
||||||
@ -130,24 +136,42 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
source: {
|
source() {
|
||||||
handler() {
|
this.msgRead();
|
||||||
this.msgRead();
|
|
||||||
},
|
|
||||||
immediate: true,
|
|
||||||
},
|
},
|
||||||
windowActive(active) {
|
windowActive(active) {
|
||||||
if (active) {
|
if (!active) {
|
||||||
this.msgRead();
|
return
|
||||||
}
|
}
|
||||||
|
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.windowActive) {
|
if (!this.windowActive) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.$el) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.$el.parentNode.classList.contains('inactive')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//
|
||||||
this.$store.dispatch("dialogMsgRead", this.source);
|
this.$store.dispatch("dialogMsgRead", this.source);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -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}"
|
:extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, scrollIng}"
|
||||||
:estimate-size="dialogData.type=='group' ? 105 : 77"
|
:estimate-size="dialogData.type=='group' ? 105 : 77"
|
||||||
:keeps="25"
|
:keeps="25"
|
||||||
:disabled="scrollDisabled"
|
:disabled="scrollDisabled"
|
||||||
@ -651,6 +651,7 @@ export default {
|
|||||||
scrollDirection: null,
|
scrollDirection: null,
|
||||||
scrollAction: 0,
|
scrollAction: 0,
|
||||||
scrollTmp: 0,
|
scrollTmp: 0,
|
||||||
|
scrollIng: 0,
|
||||||
|
|
||||||
positionLoad: 0,
|
positionLoad: 0,
|
||||||
|
|
||||||
@ -961,15 +962,11 @@ export default {
|
|||||||
if (!position_msgs || position_msgs.length === 0 || unread === 0 || this.allMsgs.length === 0) {
|
if (!position_msgs || position_msgs.length === 0 || unread === 0 || this.allMsgs.length === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const item = position_msgs.sort((a, b) => {
|
const item = $A.cloneJSON(position_msgs[0])
|
||||||
return b.msg_id - a.msg_id
|
if (item.label === '{UNREAD}') {
|
||||||
})[0]
|
item.label = this.$L(`未读消息${unread}条`)
|
||||||
if (this.allMsgs.findIndex(({id}) => id == item.msg_id) === -1) {
|
|
||||||
return Object.assign(item, {
|
|
||||||
'label': this.$L(`未读消息${unread}条`)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return null
|
return item
|
||||||
},
|
},
|
||||||
|
|
||||||
operateEmojis() {
|
operateEmojis() {
|
||||||
@ -2227,6 +2224,9 @@ export default {
|
|||||||
this.scrollAction = event.target.scrollTop;
|
this.scrollAction = event.target.scrollTop;
|
||||||
this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up';
|
this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up';
|
||||||
setTimeout(_ => this.scrollTmp = this.scrollAction, 0);
|
setTimeout(_ => this.scrollTmp = this.scrollAction, 0);
|
||||||
|
//
|
||||||
|
this.scrollIng++;
|
||||||
|
setTimeout(_=> this.scrollIng--, 100);
|
||||||
},
|
},
|
||||||
|
|
||||||
onRange(range) {
|
onRange(range) {
|
||||||
|
|||||||
@ -1254,6 +1254,11 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(100%);
|
||||||
|
animation: position-in-animation 200ms ease-out forwards;
|
||||||
|
animation-delay: 600ms;
|
||||||
|
|
||||||
.position-label {
|
.position-label {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -1973,3 +1978,14 @@ body.window-portrait {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes position-in-animation {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user