scorll-view

This commit is contained in:
2022-02-18 11:02:21 +08:00
parent 6c0feb9cb6
commit a330e79218

View File

@@ -1,9 +1,9 @@
<template> <template>
<view class="chat"> <view class="chat">
<!-- chat --> <!-- chat -->
<scroll-view class="body" scroll-y> <view class="body">
<view class="cell" v-for="(item, index) in messages" :key="index"> <view class="cell" v-for="(item, index) in messages" :key="index">
<view class="time">{{ customCN(item.sentTime) }}</view> <view class="time">{{ item.sentTime|timeCustomCN }}</view>
<view :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']"> <view :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']">
<u-avatar class="avatar" size="40" shape="square" @click="showUser(targetId, item.messageDirection)" <u-avatar class="avatar" size="40" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="contact(item.senderUserId).portraitUrl" /> :src="contact(item.senderUserId).portraitUrl" />
@@ -21,16 +21,12 @@
</view> </view>
</view> </view>
</view> </view>
<view class="cell-footer" ref="chatBottom"></view> </view>
</scroll-view>
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" /> <sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
</view> </view>
</template> </template>
<script> <script>
import {
timeCustomCN
} from '@/utils/filters.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import im from '@/utils/im/index.js' import im from '@/utils/im/index.js'
import showVoice from '../components/showVoice' import showVoice from '../components/showVoice'
@@ -38,8 +34,6 @@
import showText from '../components/showText' import showText from '../components/showText'
import sentMessageBar from '../components/sentMessageBar' import sentMessageBar from '../components/sentMessageBar'
const ChatList = uni.requireNativePlugin('dom')
export default { export default {
components: { components: {
sentMessageBar, sentMessageBar,
@@ -106,9 +100,6 @@
uni.$off('onReadReceiptReceived') uni.$off('onReadReceiptReceived')
}, },
methods: { methods: {
customCN(val) {
return timeCustomCN(val)
},
getNewMessage() { getNewMessage() {
im.getMessageList( im.getMessageList(
this.conversationType, this.conversationType,
@@ -116,10 +107,9 @@
this.latestMessage.sentTime || 0, this.latestMessage.sentTime || 0,
1, 1,
false, false,
(messages) => { (messages) => {
console.log(messages); this.messages = [...messages, ...this.messages]
this.messages = this.messages.concat(messages) // this.scrollBottom()
this.scrollBottom()
}) })
}, },
// 获取消息列表 // 获取消息列表
@@ -131,9 +121,8 @@
100, 100,
true, true,
(messages) => { (messages) => {
console.log(messages); this.messages = messages
this.messages = messages.reverse() // this.scrollBottom()
this.scrollBottom()
}) })
}, },
// 展示好友信息, type 1 是自己, 2 是对方 // 展示好友信息, type 1 是自己, 2 是对方
@@ -174,12 +163,15 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.body { .body {
flex: 1; flex: 1;
overflow: scroll; overflow-y: scroll;
display: flex;
flex-direction: column-reverse;
justify-content: flex-end;
.cell { .cell {
padding: 10rpx 30rpx; padding: 10rpx 30rpx;
.time { .time {
text-align: center; text-align: center;