键盘高度计算,改善聊天页面内容少的时候推屏的问题,但是有点卡断
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<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}">
|
||||
@@ -11,7 +11,8 @@
|
||||
</view>
|
||||
|
||||
<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" isGroup @messageAction="messageAction" />
|
||||
</view>
|
||||
@@ -51,7 +52,9 @@
|
||||
messages: [],
|
||||
groupInfo: {
|
||||
name: ''
|
||||
}
|
||||
},
|
||||
placeHeight: uni.getSystemInfoSync().windowHeight,
|
||||
bottomHeihgt: 56
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -68,7 +71,21 @@
|
||||
onShow() {
|
||||
this.initGroupInfo()
|
||||
},
|
||||
onLoad(e) {
|
||||
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.getMessageList()
|
||||
|
||||
Reference in New Issue
Block a user