From 740e6769715be978980eb09b52da7cffdbffa70e Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Fri, 21 Apr 2023 15:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E7=BE=A4=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../newMap/display/newChat/chatContent.vue | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/views/newMap/display/newChat/chatContent.vue b/src/views/newMap/display/newChat/chatContent.vue index 6c6fea7fb..87868b045 100644 --- a/src/views/newMap/display/newChat/chatContent.vue +++ b/src/views/newMap/display/newChat/chatContent.vue @@ -67,7 +67,9 @@ export default { textContent: '', currentAudioList:[], currentMessage: {}, - trainingDesign: false + trainingDesign: false, + contentDom: '', + isBottom: false }; }, computed:{ @@ -104,20 +106,37 @@ export default { this.trainingDesign = val.trainingDesign; }, lastMessage(newVal, oldVal) { - if (newVal && oldVal && (newVal.id != oldVal.id)) { + if (newVal !== oldVal && this.isBottom) { this.scrollTop(); } } }, mounted() { this.trainingDesign = this.$store.state.training.domConfig ? this.$store.state.training.domConfig.trainingDesign : false; + this.contentDom = document.querySelector('.chat-box-content'); + this.contentDom.onscroll = () => { + this.setIsBottomFn(); + }; + this.isBottom = true; this.scrollTop(); }, + beforeDestroy() { + this.contentDom.onscroll = null; + }, methods: { + setIsBottomFn() { + const scrollTop = this.contentDom.scrollHeight - this.contentDom.clientHeight; + if (scrollTop == 0 || this.contentDom.scrollTop >= scrollTop) { + this.isBottom = true; + } else { + this.isBottom = false; + } + }, scrollTop() { this.$nextTick(() => { - const scrollTop = this.messageList.length * 62; - document.querySelector('.chat-box-content').scrollTop = scrollTop; + // const scrollTop = this.messageList.length * 62; + const scrollTop = this.contentDom.scrollHeight - this.contentDom.clientHeight; + this.contentDom.scrollTop = scrollTop; }); }, playAllAudio() {