This commit is contained in:
唐明明
2022-02-18 17:39:57 +08:00
2 changed files with 89 additions and 114 deletions

View File

@@ -1,9 +1,11 @@
<template>
<view class="group--chat">
<view class="chat">
<sent-message-bar :conversationType="conversationType" :targetId="targetId" @onSuccess="getNewMessage()" />
<scroll-view class="body" :show-scrollbar="false">
<view class="body">
<view class="scroll">
<view class="cell" v-for="(item, index) in messages" :key="index">
<view class="cell-system" v-if="item.senderUserId === '__system__'">{{ item.content.message }}</view>
<view class="time" v-if="item.senderUserId === '__system__'">{{ item.content.message }}</view>
<view v-else :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']">
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
:src="contact(item.senderUserId).portraitUrl" />
@@ -17,8 +19,8 @@
</view>
</view>
</view>
<view class="cell-footer" ref="chatBottom"></view>
</scroll-view>
</view>
</view>
</view>
</template>
@@ -36,8 +38,6 @@
import showText from '../components/showText'
import sentMessageBar from '../components/sentMessageBar'
const ChatList = uni.requireNativePlugin('dom')
export default {
components: {
showVoice,
@@ -58,7 +58,7 @@
computed: {
latestMessage() {
if (this.messages.length) {
return this.messages[this.messages.length - 1]
return this.messages[0]
} else {
return {
sentTime: 0
@@ -73,10 +73,6 @@
},
onLoad(e) {
this.targetId = e.targetId
this.groupInfo = this.$store.getters.contactInfo(this.targetId)
uni.setNavigationBarTitle({
title: this.groupInfo.name
})
// 获取群成员数量
getGroupBase(this.targetId).then(res => {
uni.setNavigationBarTitle({
@@ -100,7 +96,7 @@
})
},
methods: {
onScroll(e){
onScroll(e) {
this.$refs.messageBar.onHidePopus()
},
toUser(item) {
@@ -125,7 +121,7 @@
10,
false,
(messages) => {
this.messages = this.messages.concat(messages)
this.messages.unshift(...messages)
this.scrollBottom()
})
},
@@ -135,10 +131,10 @@
this.conversationType,
this.targetId,
0,
100,
20,
true,
(messages) => {
this.messages = messages.reverse()
this.messages = messages
this.scrollBottom()
})
},
@@ -153,42 +149,43 @@
// 更新badge提醒数量
im.setNotifyBadge()
}
setTimeout(() => {
let el = this.$refs.chatBottom
ChatList.scrollToElement(el, {
offset: 0,
animated: false
})
}, 50)
}
}
}
</script>
<style lang="scss" scoped>
.group--chat {
<style scoped lang="scss">
/* 窗口 */
.chat {
background: $window-color;
height: 100vh;
display: flex;
overflow: scroll;
flex-direction: column-reverse;
.body {
overflow: scroll;
flex: 1;
height: 0;
display: flex;
flex-direction: column-reverse;
.scroll {
display: flex;
flex-direction: column-reverse;
justify-content: flex-end;
.cell {
padding: 10rpx 30rpx;
.cell-system {
.time {
text-align: center;
font-size: 24rpx;
color: #666;
}
.cell-item {
display: flex;
flex-direction: row;
width: 690rpx;
justify-content: flex-start;
align-items: flex-start;
margin-top: 20rpx;
&.left {
flex-direction: row;
@@ -203,19 +200,21 @@
}
}
.avatar {
width: 78rpx;
height: 78rpx;
background-color: white;
border-radius: 10rpx;
}
.msg {
margin: 0 20rpx;
.user {
font-size: 18rpx;
line-height: 40rpx;
.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;
}
}
}
}
@@ -225,31 +224,6 @@
}
}
}
.footer {
background: white;
padding: 20rpx 30rpx;
display: flex;
justify-content: space-between;
flex-direction: row;
.msg-type {
width: 70rpx;
height: 70rpx;
.icon {
margin: 5rpx;
width: 60rpx;
height: 60rpx;
}
}
}
}
.message-bar{
position: fixed;
bottom: 0;
left: 0;
right: 0;
}
</style>

View File

@@ -119,7 +119,7 @@
this.conversationType,
this.targetId,
0,
100,
20,
true,
(messages) => {
this.messages = messages
@@ -148,6 +148,7 @@
}
}
</script>
<style scoped lang="scss">
/* 窗口 */
.chat {