From c0342ea6d108340f52509a688feff91ae512229e Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 14 Dec 2023 19:56:06 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=9C=AA=E8=AF=BB?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/pages/manage/components/DialogItem.vue | 48 ++++++++++++++----- .../pages/manage/components/DialogWrapper.vue | 18 +++---- .../sass/pages/components/dialog-wrapper.scss | 16 +++++++ 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/resources/assets/js/pages/manage/components/DialogItem.vue b/resources/assets/js/pages/manage/components/DialogItem.vue index d619879e3..464ec93e2 100644 --- a/resources/assets/js/pages/manage/components/DialogItem.vue +++ b/resources/assets/js/pages/manage/components/DialogItem.vue @@ -93,25 +93,31 @@ export default { type: Number, default: 0 }, + scrollIng: { + type: Number, + default: 0 + }, }, - data() { - return { - subscribe: null, - } + mounted() { + this.checkWatch() }, computed: { ...mapState(['userId']), isRightMsg() { - return this.source.userid == this.userId + return this.source.userid == this.$store.state.userId }, isReply() { return this.simpleView || this.msgId === this.source.id }, + isNoWatch() { + return this.isRightMsg || this.source.read_at + }, + hidePercentage() { return this.simpleView || this.isMyDialog || this.isReply }, @@ -130,24 +136,42 @@ export default { }, watch: { - source: { - handler() { - this.msgRead(); - }, - immediate: true, + source() { + this.msgRead(); }, windowActive(active) { - if (active) { - this.msgRead(); + if (!active) { + return } + this.msgRead(); } }, methods: { + checkWatch() { + if (this.isNoWatch) { + return + } + const watchr = this.$watch("scrollIng", _ => { + if (this.isNoWatch) { + watchr() + return + } + this.msgRead() + }) + }, + msgRead() { if (!this.windowActive) { return; } + if (!this.$el) { + return; + } + if (this.$el.parentNode.classList.contains('inactive')) { + return; + } + // this.$store.dispatch("dialogMsgRead", this.source); }, diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 0e3cc5573..2c3511a46 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -155,7 +155,7 @@ :data-component="msgItem" :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" :keeps="25" :disabled="scrollDisabled" @@ -651,6 +651,7 @@ export default { scrollDirection: null, scrollAction: 0, scrollTmp: 0, + scrollIng: 0, positionLoad: 0, @@ -961,15 +962,11 @@ export default { if (!position_msgs || position_msgs.length === 0 || unread === 0 || this.allMsgs.length === 0) { return null } - const item = position_msgs.sort((a, b) => { - return b.msg_id - a.msg_id - })[0] - if (this.allMsgs.findIndex(({id}) => id == item.msg_id) === -1) { - return Object.assign(item, { - 'label': this.$L(`未读消息${unread}条`) - }) + const item = $A.cloneJSON(position_msgs[0]) + if (item.label === '{UNREAD}') { + item.label = this.$L(`未读消息${unread}条`) } - return null + return item }, operateEmojis() { @@ -2227,6 +2224,9 @@ export default { this.scrollAction = event.target.scrollTop; this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up'; setTimeout(_ => this.scrollTmp = this.scrollAction, 0); + // + this.scrollIng++; + setTimeout(_=> this.scrollIng--, 100); }, onRange(range) { diff --git a/resources/assets/sass/pages/components/dialog-wrapper.scss b/resources/assets/sass/pages/components/dialog-wrapper.scss index 23104027a..b2224528d 100644 --- a/resources/assets/sass/pages/components/dialog-wrapper.scss +++ b/resources/assets/sass/pages/components/dialog-wrapper.scss @@ -1254,6 +1254,11 @@ display: flex; align-items: center; justify-content: flex-end; + opacity: 0; + transform: translateX(100%); + animation: position-in-animation 200ms ease-out forwards; + animation-delay: 600ms; + .position-label { display: flex; 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); + } +}