Browse Source

保证聊天室在第一次打开时,滚动条在最底部

jubs 2 months ago
parent
commit
5d7c9bb704
1 changed files with 11 additions and 4 deletions
  1. 11 4
      ruoyi-ui-vue2/src/components/FloatingComponent/index.vue

+ 11 - 4
ruoyi-ui-vue2/src/components/FloatingComponent/index.vue

@@ -228,6 +228,7 @@ export default {
       activeChatRoom: {},
       activeChatRoom: {},
       activeScrollTop: 0,
       activeScrollTop: 0,
       avatarPrefix: process.env.VUE_APP_BASE_API,
       avatarPrefix: process.env.VUE_APP_BASE_API,
+      firstEnter: 0,
 
 
     };
     };
   },
   },
@@ -375,7 +376,7 @@ export default {
       }).finally(() => {
       }).finally(() => {
         this.$nextTick(() => {
         this.$nextTick(() => {
           const div = document.getElementById('messageList')
           const div = document.getElementById('messageList')
-          if (div){
+          if (div) {
             div.scrollTop = div.scrollHeight
             div.scrollTop = div.scrollHeight
           }
           }
         })
         })
@@ -394,7 +395,10 @@ export default {
       }).finally(() => {
       }).finally(() => {
         this.$nextTick(() => {
         this.$nextTick(() => {
           const div = document.getElementById('messageList')
           const div = document.getElementById('messageList')
-          if (div){
+          if (this.firstEnter) {
+            this.activeScrollTop = div.scrollHeight;
+          }
+          if (div) {
             div.scrollTop = div.scrollHeight
             div.scrollTop = div.scrollHeight
           }
           }
         })
         })
@@ -483,8 +487,9 @@ export default {
       if (this.popUpFlag) {
       if (this.popUpFlag) {
         setTimeout(() => {
         setTimeout(() => {
           const scroll = document.getElementById('messageList');
           const scroll = document.getElementById('messageList');
-          if (scroll){
+          if (scroll) {
             scroll.addEventListener('scroll', that.scrollHandle, true);
             scroll.addEventListener('scroll', that.scrollHandle, true);
+            //如果是第一次进入,则滚动至底部
             scroll.scrollTo({
             scroll.scrollTo({
               top: this.activeScrollTop,
               top: this.activeScrollTop,
               behavior: 'smooth'
               behavior: 'smooth'
@@ -492,9 +497,12 @@ export default {
           }
           }
         }, 200)
         }, 200)
 
 
+
       } else {
       } else {
         this.$set(this.queryParams, 'chatName', null)
         this.$set(this.queryParams, 'chatName', null)
       }
       }
+
+      this.firstEnter++;
     }
     }
 
 
   },
   },
@@ -524,7 +532,6 @@ export default {
 
 
           }
           }
           await this.handleQueryContentList(this.activeChatRoom);
           await this.handleQueryContentList(this.activeChatRoom);
-
           this.messageShow = true
           this.messageShow = true
           this.totalQty = isNaN(Number(val.chatRoomsTotal)) ? 0 : Number(val.chatRoomsTotal);
           this.totalQty = isNaN(Number(val.chatRoomsTotal)) ? 0 : Number(val.chatRoomsTotal);
           // 是否弹出消息列表
           // 是否弹出消息列表