聊天列表自动到底,如果列表数据较短的时候,还没有好办法实现

This commit is contained in:
2022-02-18 17:02:32 +08:00
parent 0deef8bc6a
commit e957217635
2 changed files with 69 additions and 65 deletions

View File

@@ -1,29 +1,31 @@
<template>
<view class="chat">
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
<!-- chat -->
<view class="body">
<view class="cell" v-for="(item, index) in messages" :key="index">
<view class="time">{{ item.sentTime|timeCustomCN }}</view>
<view :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']">
<u-avatar class="avatar" size="40" shape="square"
@click="showUser(item.senderUserId, item.messageDirection)"
:src="contact(item.senderUserId).portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<view class="state" v-if="item.messageDirection == 1">
<text
:class="item.sentStatus === 50?'state-text':'state-text-active'">{{ item.sentStatus == 50 ? '已读': '未读'}}</text>
<view class="scroll">
<view class="cell" v-for="(item, index) in messages" :key="index">
<view class="time">{{ item.sentTime|timeCustomCN }}</view>
<view :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']">
<u-avatar class="avatar" size="40" shape="square"
@click="showUser(item.senderUserId, item.messageDirection)"
:src="contact(item.senderUserId).portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
<view class="state" v-if="item.messageDirection == 1">
<text
:class="item.sentStatus === 50?'state-text':'state-text-active'">{{ item.sentStatus == 50 ? '已读': '未读'}}</text>
</view>
</view>
</view>
</view>
</view>
</view>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view>
</template>
@@ -108,10 +110,9 @@
this.latestMessage.sentTime || 0,
1,
false,
(messages) => {
console.log(messages);
(messages) => {
this.messages.unshift(...messages)
// this.scrollBottom()
this.scrollBottom()
})
},
// 获取消息列表
@@ -124,7 +125,7 @@
true,
(messages) => {
this.messages = messages
// this.scrollBottom()
this.scrollBottom()
})
},
// 展示好友信息, type 1 是自己, 2 是对方
@@ -145,13 +146,6 @@
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom
ChatList.scrollToElement(el, {
offset: 0,
animated: false
})
}, 50)
}
}
}
@@ -160,65 +154,72 @@
<style scoped lang="scss">
/* 窗口 */
.chat {
background: $window-color;
height: 100vh;
display: flex;
flex-direction: column;
overflow: scroll;
flex-direction: column-reverse;
.body {
overflow: scroll;
flex: 1;
height: 0;
display: flex;
flex-direction: column-reverse;
justify-content: flex-end;
.cell {
padding: 10rpx 30rpx;
.scroll {
display: flex;
flex-direction: column-reverse;
justify-content: flex-end;
.time {
text-align: center;
font-size: 24rpx;
color: #666;
}
.cell {
padding: 10rpx 30rpx;
.cell-item {
display: flex;
width: 690rpx;
justify-content: flex-start;
&.left {
flex-direction: row;
.time {
text-align: center;
font-size: 24rpx;
color: #666;
}
&.right {
flex-direction: row-reverse;
.cell-item {
display: flex;
width: 690rpx;
justify-content: flex-start;
.state {
&.left {
flex-direction: row;
justify-content: flex-end;
}
}
.msg {
margin: 0 20rpx;
&.right {
flex-direction: row-reverse;
.state {
padding-top: 10rpx;
.state-text {
font-size: $title-size-m - 2;
color: rgba($color: $main-color, $alpha: 0.3)
.state {
flex-direction: row;
justify-content: flex-end;
}
}
.state-text-active {
font-size: $title-size-m - 2;
color: #cecece;
.msg {
margin: 0 20rpx;
.state {
padding-top: 10rpx;
.state-text {
font-size: $title-size-m - 2;
color: rgba($color: $main-color, $alpha: 0.3)
}
.state-text-active {
font-size: $title-size-m - 2;
color: #cecece;
}
}
}
}
}
.cell-footer {
height: 20rpx;
.cell-footer {
height: 20rpx;
}
}
}
}