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

View File

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