Browse Source

优化: ios h5上拉消息滚动条异常问题

master
xsx 10 months ago
parent
commit
6313b49f43
  1. 54
      im-uniapp/pages/chat/chat-box.vue

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

@ -4,15 +4,17 @@
<view class="chat-main-box" :style="{height: chatMainHeight+'px'}"> <view class="chat-main-box" :style="{height: chatMainHeight+'px'}">
<view class="chat-message" @click="switchChatTabBox('none')"> <view class="chat-message" @click="switchChatTabBox('none')">
<scroll-view class="scroll-box" scroll-y="true" upper-threshold="200" @scrolltoupper="onScrollToTop" <scroll-view class="scroll-box" scroll-y="true" upper-threshold="200" @scrolltoupper="onScrollToTop"
:scroll-into-view="'chat-item-' + scrollMsgIdx"> @scroll="onScroll" :scroll-into-view="'chat-item-' + scrollMsgIdx" :scroll-top="scrollTop">
<view v-if="chat" v-for="(msgInfo, idx) in chat.messages" :key="idx"> <view v-if="chat" class="chat-wrap">
<chat-message-item :ref="'message'+msgInfo.id" v-if="idx >= showMinIdx" <view v-for="(msgInfo, idx) in chat.messages" :key="idx">
:headImage="headImage(msgInfo)" @call="onRtCall(msgInfo)" :showName="showName(msgInfo)" <chat-message-item :ref="'message'+msgInfo.id" v-if="idx >= showMinIdx"
@recall="onRecallMessage" @delete="onDeleteMessage" @copy="onCopyMessage" :headImage="headImage(msgInfo)" @call="onRtCall(msgInfo)" :showName="showName(msgInfo)"
@longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile" @recall="onRecallMessage" @delete="onDeleteMessage" @copy="onCopyMessage"
@audioStateChange="onAudioStateChange" :id="'chat-item-' + idx" :msgInfo="msgInfo" @longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile"
:groupMembers="groupMembers"> @audioStateChange="onAudioStateChange" :id="'chat-item-' + idx" :msgInfo="msgInfo"
</chat-message-item> :groupMembers="groupMembers">
</chat-message-item>
</view>
</view> </view>
</scroll-view> </scroll-view>
<view v-if="!isInBottom" class="scroll-to-bottom" @click="onClickToBottom"> <view v-if="!isInBottom" class="scroll-to-bottom" @click="onClickToBottom">
@ -133,7 +135,7 @@ export default {
keyboardHeight: 290, // keyboardHeight: 290, //
windowHeight: 1000, // windowHeight: 1000, //
initHeight: 1000, // h5 initHeight: 1000, // h5
atUserIds: [], atUserIds: [],
showMinIdx: 0, // showMinIdx showMinIdx: 0, // showMinIdx
reqQueue: [], // reqQueue: [], //
isSending: false, // isSending: false, //
@ -144,7 +146,9 @@ export default {
isReadOnly: false, // isReadOnly: false, //
playingAudio: null, // playingAudio: null, //
isInBottom: true, // isInBottom: true, //
newMessageSize: 0 // newMessageSize: 0, //
scrollTop: 0, // ios h5
scrollViewHeight: 0 //
} }
}, },
methods: { methods: {
@ -574,12 +578,20 @@ export default {
this.newMessageSize = 0; this.newMessageSize = 0;
}, 100) }, 100)
}, },
onScroll(e) {
//
this.scrollViewHeight = e.detail.scrollHeight;
},
onScrollToTop() { onScrollToTop() {
if (this.showMinIdx > 0) { if (this.showMinIdx > 0) {
// #ifndef H5 // #ifndef H5
// // appscroll-into-view
this.scrollToMsgIdx(this.showMinIdx); this.scrollToMsgIdx(this.showMinIdx);
// #endif // #endif
// #ifdef H5
// h5scroll-top
this.holdingScrollBar(this.scrollViewHeight);
// #endif
// 20 // 20
this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0; this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
} }
@ -591,6 +603,20 @@ export default {
this.isInBottom = true; this.isInBottom = true;
this.newMessageSize = 0; this.newMessageSize = 0;
}, },
holdingScrollBar(scrollViewHeight) {
//
const query = uni.createSelectorQuery().in(this);
setTimeout(() => {
query.select('.chat-wrap').boundingClientRect();
query.exec(data => {
this.scrollTop = data[0].height - scrollViewHeight;
if(this.scrollTop < 10){
//
this.holdingScrollBar();
}
});
}, 50)
},
onShowMore() { onShowMore() {
if (this.chat.type == "GROUP") { if (this.chat.type == "GROUP") {
uni.navigateTo({ uni.navigateTo({
@ -973,7 +999,7 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.windowHeight = uni.getSystemInfoSync().windowHeight; this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.reCalChatMainHeight(); this.reCalChatMainHeight();
this.scrollToBottom();
// #ifdef H5 // #ifdef H5
this.initHeight = window.innerHeight; this.initHeight = window.innerHeight;
// iosh5: // iosh5:

Loading…
Cancel
Save