键盘高度计算,改善聊天页面内容少的时候推屏的问题,但是有点卡断
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<view class="header">
|
||||
<view class="name">
|
||||
{{ contact(item.targetId).name }}
|
||||
<!-- <text v-if="item.conversationType === 3" class='group'>[群]</text> -->
|
||||
<text v-if="item.conversationType === 3" class='group'>[群]</text>
|
||||
</view>
|
||||
<view class="time">{{ item.sentTime|timeCustomCN }}</view>
|
||||
</view>
|
||||
|
||||
@@ -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: {
|
||||
@@ -69,6 +72,20 @@
|
||||
this.initGroupInfo()
|
||||
},
|
||||
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()
|
||||
|
||||
@@ -12,6 +12,9 @@ export default {
|
||||
},
|
||||
sender() {
|
||||
return this.$store.getters.sender
|
||||
},
|
||||
windowHeight() {
|
||||
return uni.getSystemInfoSync().windowHeight
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -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>
|
||||
@@ -46,7 +48,9 @@
|
||||
name: '',
|
||||
userId: '',
|
||||
portraitUrl: ''
|
||||
}
|
||||
},
|
||||
placeHeight: uni.getSystemInfoSync().windowHeight,
|
||||
bottomHeihgt: 56
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -66,6 +70,20 @@
|
||||
})
|
||||
},
|
||||
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,6 +124,9 @@
|
||||
})
|
||||
},
|
||||
onUnload() {
|
||||
uni.offKeyboardHeightChange(res => {
|
||||
console.log('卸载监听键盘高度变化', res);
|
||||
})
|
||||
uni.$off('onUserDelete_' + this.targetId)
|
||||
uni.$off('onReceiveMessage_' + this.targetId)
|
||||
uni.$off('onRecallMessage_' + this.targetId)
|
||||
@@ -160,6 +181,8 @@
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.place {}
|
||||
|
||||
/* 窗口 */
|
||||
.chat {
|
||||
background: $window-color;
|
||||
|
||||
@@ -73,6 +73,7 @@ const connect = (token, userInfo, callback) => {
|
||||
key: FK,
|
||||
success: () => {
|
||||
contactModel.find((err, results) => {
|
||||
console.log('初始化联系人信息', results);
|
||||
results.map(item => {
|
||||
store.dispatch('launchContact', item)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user