From 405e5aa03aed13932fb5aef86bc2a9a136501c8f Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 22 Feb 2023 08:35:30 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=86=8D=E6=AC=A1=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=9B=BE=E6=A0=87=E9=97=AA=E5=8A=A8=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/js/components/Mobile/Tabbar.vue | 3 ++ .../assets/js/pages/manage/messenger.vue | 41 +++++++++++++------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/resources/assets/js/components/Mobile/Tabbar.vue b/resources/assets/js/components/Mobile/Tabbar.vue index 7e6af0573..b8d1ce662 100644 --- a/resources/assets/js/components/Mobile/Tabbar.vue +++ b/resources/assets/js/components/Mobile/Tabbar.vue @@ -262,6 +262,9 @@ export default { case 'dialog': location = {name: 'manage-messenger', params: {dialogAction: 'dialog'}}; + if (this.routeName === 'manage-messenger') { + Store.set('clickAgainDialog', true); + } break; case 'contacts': diff --git a/resources/assets/js/pages/manage/messenger.vue b/resources/assets/js/pages/manage/messenger.vue index 47e044ebe..a393d0d0e 100644 --- a/resources/assets/js/pages/manage/messenger.vue +++ b/resources/assets/js/pages/manage/messenger.vue @@ -160,6 +160,7 @@ import {mapState} from "vuex"; import DialogWrapper from "./components/DialogWrapper"; import ScrollerY from "../../components/ScrollerY"; import longpress from "../../directives/longpress"; +import {Store} from "le5le-store"; export default { components: {ScrollerY, DialogWrapper}, @@ -191,6 +192,8 @@ export default { operateItem: {}, operateStyles: {}, operateVisible: false, + + clickAgainSubscribe: null, } }, @@ -199,6 +202,16 @@ export default { if (id > 0) { this.openDialog(id) } + this.clickAgainSubscribe = Store.subscribe('clickAgainDialog', this.shakeUnread); + }, + + beforeDestroy() { + if (this.clickAgainSubscribe) { + this.clickAgainSubscribe.unsubscribe(); + this.clickAgainSubscribe = null; + } + // + document.removeEventListener('keydown', this.shortcutEvent); }, activated() { @@ -484,22 +497,26 @@ export default { } if (this.dialogActive == type) { // 再次点击滚动到未读条目 - let index = this.dialogList.findIndex(dialog => $A.getDialogNum(dialog) > 0) - if (index === -1) { - index = this.dialogList.findIndex(dialog => $A.getDialogUnread(dialog, true) > 0) - } - if (index > -1) { - const el = this.$refs[`dialog_${this.dialogList[index]?.id}`][0] - $A.scrollToView(el, {behavior: "smooth", block, inline: "nearest"}) - requestAnimationFrame(_ => { - $A(el).addClass("common-shake") - setTimeout(_ => $A(el).removeClass("common-shake"), 1000) - }) - } + this.shakeUnread() } this.dialogActive = type }, + shakeUnread() { + let index = this.dialogList.findIndex(dialog => $A.getDialogNum(dialog) > 0) + if (index === -1) { + index = this.dialogList.findIndex(dialog => $A.getDialogUnread(dialog, true) > 0) + } + if (index > -1) { + const el = this.$refs[`dialog_${this.dialogList[index]?.id}`][0] + if (el) { + $A.scrollIntoViewIfNeeded(el) + el.classList.remove("common-shake") + requestAnimationFrame(_ => el.classList.add("common-shake")) + } + } + }, + dialogClass(dialog) { if (this.dialogKey) { return null