键盘高度计算,改善聊天页面内容少的时候推屏的问题,但是有点卡断

This commit is contained in:
2022-02-28 12:15:11 +08:00
parent e8e496cf37
commit bf94cca533
5 changed files with 67 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
<template>
<view class="chat">
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
<sent-message-bar id="msgbar" :conversationType="conversationType" :targetId="targetId"
@onSuccess="getNewMessage()" />
<view class="shade" @click="hidePop" v-show="showPop">
<view class="pop" :style="popStyle" :class="{'show':showPop}">
<view v-for="(item, index) in popButton" :key="index" @click="pickerMenu(item)">
@@ -10,7 +11,8 @@
</view>
<!-- chat -->
<view class="body">
<view class="scroll">
<view class="place" :style="{ height: placeHeight + 'px' }"></view>
<view class="scroll" id="scroll">
<view class="cell" v-for="(message, index) in messages" :key="index">
<show-message-cell :message="message" @messageAction="messageAction" />
</view>
@@ -26,11 +28,11 @@
import showMessageCell from '../components/showMessageCell'
import utils from '@/utils/index.js'
import imBase from '../mixins/imBase.js'
import messageActions from '../mixins/messageActions.js'
import messageActions from '../mixins/messageActions.js'
export default {
mixins: [
imBase,
imBase,
messageActions
],
components: {
@@ -46,7 +48,9 @@
name: '',
userId: '',
portraitUrl: ''
}
},
placeHeight: uni.getSystemInfoSync().windowHeight,
bottomHeihgt: 56
}
},
computed: {
@@ -59,13 +63,27 @@
}
}
}
},
onShow() {
uni.setNavigationBarTitle({
title: this.contact(this.targetId).name
})
},
onLoad(e) {
onShow() {
uni.setNavigationBarTitle({
title: this.contact(this.targetId).name
})
},
onLoad(e) {
const query = uni.createSelectorQuery().in(this);
this.$nextTick(function() {
query.select('#msgbar').boundingClientRect(bottom => {
this.bottomHeihgt = bottom.height
}).exec();
})
// 监听键盘高度变化
uni.onKeyboardHeightChange(keyboard => {
query.select('#scroll').boundingClientRect(scroll => {
const placeHeight = this.windowHeight - scroll.height - keyboard.height - this
.bottomHeihgt
this.placeHeight = placeHeight > 0 ? placeHeight : 0
}).exec();
})
this.targetId = e.targetId
this.userInfo = this.$store.getters.contactInfo(this.targetId)
// 获取消息列表
@@ -106,16 +124,19 @@
})
},
onUnload() {
uni.offKeyboardHeightChange(res => {
console.log('卸载监听键盘高度变化', res);
})
uni.$off('onUserDelete_' + this.targetId)
uni.$off('onReceiveMessage_' + this.targetId)
uni.$off('onRecallMessage_' + this.targetId)
uni.$off('onRecallMessage')
uni.$off('onReadReceiptReceived')
},
onNavigationBarButtonTap() {
uni.navigateTo({
url:'/pages/im/friends/info?targetId='+this.targetId
})
},
onNavigationBarButtonTap() {
uni.navigateTo({
url: '/pages/im/friends/info?targetId=' + this.targetId
})
},
methods: {
getNewMessage() {
@@ -160,6 +181,8 @@
</script>
<style scoped lang="scss">
.place {}
/* 窗口 */
.chat {
background: $window-color;