Browse Source

增加回到消息底部功能

master
xsx 10 months ago
parent
commit
ab9763fd94
  1. 65
      im-uniapp/pages/chat/chat-box.vue
  2. 146
      im-web/src/components/chat/ChatBox.vue

65
im-uniapp/pages/chat/chat-box.vue

@ -15,6 +15,9 @@
</chat-message-item>
</view>
</scroll-view>
<view v-if="!isInBottom" class="scroll-to-bottom" @click="onClickToBottom">
{{ newMessageSize > 0 ? newMessageSize+'条新消息' :'回到底部'}}
</view>
</view>
<view v-if="atUserIds.length > 0" class="chat-at-bar" @click="openAtBox()">
<view class="iconfont icon-at">&nbsp;</view>
@ -140,7 +143,9 @@ export default {
isEmpty: true, //
isFocus: false, //
isReadOnly: false, //
playingAudio: null //
playingAudio: null, //
isInBottom: true, //
newMessageSize: 0 //
}
},
methods: {
@ -561,17 +566,32 @@ export default {
}
});
},
onClickToBottom() {
this.scrollToBottom();
//
// 100s
setTimeout(() => {
this.isInBottom = true;
this.newMessageSize = 0;
}, 100)
},
onScrollToTop() {
if (this.showMinIdx == 0) {
console.log("消息已滚动到顶部")
return;
console.log("onScrollToTop")
if (this.showMinIdx > 0) {
// #ifndef H5
//
this.scrollToMsgIdx(this.showMinIdx);
// #endif
// 20
this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
}
// #ifndef H5
//
this.scrollToMsgIdx(this.showMinIdx);
// #endif
// 20
this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
//
this.isInBottom = false;
},
onScrollToBottom(e) {
//
this.isInBottom = true;
this.newMessageSize = 0;
},
onShowMore() {
if (this.chat.type == "GROUP") {
@ -639,7 +659,6 @@ export default {
method: 'PUT'
}).then(() => {
this.chatStore.resetUnreadCount(this.chat)
this.scrollToBottom();
})
},
loadGroup(groupId) {
@ -907,12 +926,12 @@ export default {
messageSize: function(newSize, oldSize) {
//
if (newSize > oldSize) {
let pages = getCurrentPages();
let curPage = pages[pages.length - 1].route;
if (curPage == "pages/chat/chat-box") {
if (this.isInBottom) {
// ,
this.scrollToBottom();
} else {
this.needScrollToBottom = true;
//
this.newMessageSize++;
}
}
},
@ -949,7 +968,8 @@ export default {
//
this.$nextTick(() => {
this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.reCalChatMainHeight()
this.reCalChatMainHeight();
this.scrollToBottom();
// #ifdef H5
this.initHeight = window.innerHeight;
// iosh5:
@ -1025,6 +1045,19 @@ export default {
.scroll-box {
height: 100%;
}
.scroll-to-bottom {
position: absolute;
right: 30rpx;
bottom: 30rpx;
font-size: $im-font-size;
color: $im-color-primary;
font-weight: 600;
background: white;
padding: 10rpx 30rpx;
border-radius: 25rpx;
box-shadow: $im-box-shadow-dark;
}
}
.chat-at-bar {

146
im-web/src/components/chat/ChatBox.vue

@ -22,6 +22,9 @@
</ul>
</div>
</el-main>
<div v-if="!isInBottom" class="scroll-to-bottom" @click="scrollToBottom">
{{ newMessageSize > 0 ? newMessageSize + '条新消息' : '回到底部' }}
</div>
<el-footer height="220px" class="im-chat-footer">
<div class="chat-tool-bar">
<div title="表情" class="icon iconfont icon-emoji" ref="emotion"
@ -129,8 +132,10 @@ export default {
showHistory: false, //
lockMessage: false, //
showMinIdx: 0, // showMinIdx
reqQueue: [],
isSending: false
reqQueue: [], //
isSending: false, //
isInBottom: false, //
newMessageSize: 0 //
}
},
methods: {
@ -276,6 +281,12 @@ export default {
if (scrollTop < 30) { // ,
// 20
this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
this.isInBottom = false;
}
//
if (scrollTop + scrollElement.clientHeight >= scrollElement.scrollHeight - 30) {
this.isInBottom = true;
this.newMessageSize = 0;
}
},
showEmotionBox() {
@ -729,8 +740,13 @@ export default {
messageSize: {
handler(newSize, oldSize) {
if (newSize > oldSize) {
//
this.scrollToBottom();
if (this.isInBottom) {
//
this.scrollToBottom();
} else {
//
this.newMessageSize++;
}
}
}
}
@ -767,72 +783,92 @@ export default {
}
}
.im-chat-main {
padding: 0;
background-color: #fff;
.content-box {
position: relative;
.im-chat-main {
padding: 0;
background-color: #fff;
.im-chat-box {
>ul {
padding: 0 20px;
.im-chat-box {
>ul {
padding: 0 20px;
li {
list-style-type: none;
li {
list-style-type: none;
}
}
}
}
}
.im-chat-footer {
display: flex;
flex-direction: column;
padding: 0;
.scroll-to-bottom {
text-align: right;
position: absolute;
right: 20px;
bottom: 230px;
color: var(--im-color-primary);
font-size: var(--im-font-size);
font-weight: 600;
background: #eee;
padding: 5px 15px;
border-radius: 15px;
cursor: pointer;
z-index: 99;
box-shadow: var(--im-box-shadow-light);
}
.chat-tool-bar {
.im-chat-footer {
display: flex;
position: relative;
width: 100%;
height: 36px;
text-align: left;
box-sizing: border-box;
border-top: var(--im-border);
padding: 4px 2px 2px 8px;
flex-direction: column;
padding: 0;
.chat-tool-bar {
display: flex;
position: relative;
width: 100%;
height: 36px;
text-align: left;
box-sizing: border-box;
border-top: var(--im-border);
padding: 4px 2px 2px 8px;
>div {
font-size: 22px;
cursor: pointer;
line-height: 30px;
width: 30px;
height: 30px;
text-align: center;
border-radius: 2px;
margin-right: 8px;
color: #999;
transition: 0.3s;
>div {
font-size: 22px;
cursor: pointer;
line-height: 30px;
width: 30px;
height: 30px;
text-align: center;
border-radius: 2px;
margin-right: 8px;
color: #999;
transition: 0.3s;
&.chat-tool-active {
font-weight: 600;
color: var(--im-color-primary);
background-color: #ddd;
&.chat-tool-active {
font-weight: 600;
color: var(--im-color-primary);
background-color: #ddd;
}
}
}
>div:hover {
color: #333;
>div:hover {
color: #333;
}
}
}
.send-content-area {
position: relative;
display: flex;
flex-direction: column;
height: 100%;
background-color: white !important;
.send-content-area {
position: relative;
display: flex;
flex-direction: column;
height: 100%;
background-color: white !important;
.send-btn-area {
padding: 10px;
position: absolute;
bottom: 4px;
right: 6px;
.send-btn-area {
padding: 10px;
position: absolute;
bottom: 4px;
right: 6px;
}
}
}
}

Loading…
Cancel
Save