群的系统消息

This commit is contained in:
2022-02-17 09:37:05 +08:00
parent dfc58676f9
commit 3a3517b5be
4 changed files with 81 additions and 48 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -3,13 +3,16 @@
<view class="users"> <view class="users">
<view :class="['user', {'active': item.targetId == currentUser.targetId}]" @longpress="showAction(item)" <view :class="['user', {'active': item.targetId == currentUser.targetId}]" @longpress="showAction(item)"
v-for="(item, index) in users" :key="index" @click="toUser(item)"> v-for="(item, index) in users" :key="index" @click="toUser(item)">
<u-avatar :size="avatarSize" shape="square" :src="contact(item.targetId).portraitUrl"></u-avatar> <view class="avatar">
<u-avatar :size="avatarSize" shape="square" :src="contact(item.targetId).portraitUrl"></u-avatar>
<view class="admin" v-if="item.is_admin">管理</view>
<view class="owner" v-if="item.targetId === adminUid">群主</view>
</view>
<view class="name">{{ item.name }}</view> <view class="name">{{ item.name }}</view>
<view class="admin" v-if="item.is_admin">管理</view>
<view class="owner" v-if="item.targetId === adminUid">群主</view>
</view> </view>
<view class="user" v-if="isAdmin"> <view class="user" v-if="isAdmin">
<u-avatar @click="inviteUser" shape="square" icon="plus" bg-color="#eeeeee" color="#999999"> <u-avatar @click="inviteUser" :size="avatarSize" shape="square" icon="plus" bg-color="#eeeeee"
color="#999999">
</u-avatar> </u-avatar>
<view class="name">邀请好友</view> <view class="name">邀请好友</view>
</view> </view>
@@ -58,17 +61,16 @@
currentUser: {}, currentUser: {},
avatarSize: 40 avatarSize: 40
} }
}, },
computed: { computed: {
contact() { contact() {
return function(targetId) { return function(targetId) {
return this.$store.getters.contactInfo(targetId) return this.$store.getters.contactInfo(targetId)
} }
} }
}, },
created() { created() {
this.avatarSize = 126 / 750 * wx.getSystemInfoSync().windowWidth this.avatarSize = 90 / 750 * wx.getSystemInfoSync().windowWidth
console.log(this.avatarSize)
}, },
mounted() { mounted() {
this.initGroupInfo() this.initGroupInfo()
@@ -237,7 +239,6 @@
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.users { .users {
flex-direction: row; flex-direction: row;
@@ -246,8 +247,6 @@
padding: 20rpx 0; padding: 20rpx 0;
.user { .user {
overflow: hidden;
position: relative;
width: 126rpx; width: 126rpx;
margin-left: 20rpx; margin-left: 20rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
@@ -255,12 +254,46 @@
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
border-radius: 0 10rpx 0 0;
&.active { &.active {
background-color: $window-color; background-color: $window-color;
} }
.avatar {
border-radius: 0 8rpx 0 0;
position: relative;
width: 90rpx;
height: 90rpx;
overflow: hidden;
.admin {
position: absolute;
background-color: $main-color;
transform: rotate(45deg);
color: #ffffff;
font-size: 12rpx;
width: 100rpx;
padding-top: 30rpx;
text-align: center;
right: -45rpx;
top: -20rpx;
}
.owner {
position: absolute;
background-color: $text-price;
transform: rotate(45deg);
color: #ffffff;
font-size: 12rpx;
width: 100rpx;
padding-top: 30rpx;
text-align: center;
right: -45rpx;
top: -20rpx;
}
}
.name { .name {
color: $text-gray-m; color: $text-gray-m;
width: 126rpx; width: 126rpx;
@@ -272,31 +305,6 @@
word-break: break-word; word-break: break-word;
} }
.admin {
position: absolute;
background-color: $main-color;
transform: rotate(45deg);
color: #ffffff;
font-size: 12rpx;
width: 100rpx;
padding-top: 30rpx;
text-align: center;
right: -45rpx;
top: -20rpx;
}
.owner {
position: absolute;
background-color: $text-price;
transform: rotate(45deg);
color: #ffffff;
font-size: 12rpx;
width: 100rpx;
padding-top: 30rpx;
text-align: center;
right: -45rpx;
top: -20rpx;
}
} }
} }

View File

@@ -2,7 +2,10 @@
<view class="group--chat"> <view class="group--chat">
<list class="body" :show-scrollbar="false"> <list class="body" :show-scrollbar="false">
<cell class="cell" v-for="(item, index) in messages" :key="index"> <cell class="cell" v-for="(item, index) in messages" :key="index">
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'"> <view class="cell-system" v-if="item.senderUserId === '__system__'">
<text class="text">{{ item.content.content }}</text>
</view>
<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" />
<view class="msg"> <view class="msg">
@@ -25,6 +28,9 @@
import { import {
timeCustomCN timeCustomCN
} from '@/utils/filters.js' } from '@/utils/filters.js'
import {
getGroupBase
} from '@/apis/interfaces/im.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'
@@ -73,12 +79,21 @@
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: this.groupInfo.name title: this.groupInfo.name
}) })
// 获取群成员数量
getGroupBase(this.targetId).then(res => {
uni.setNavigationBarTitle({
title: this.groupInfo.name + `(${res.members})`
})
})
// 获取历史消息列表
this.getMessageList() this.getMessageList()
// 监听收到本群的消息,追加消息
uni.$on('onReceiveMessage', (msg) => { uni.$on('onReceiveMessage', (msg) => {
if (msg.targetId == this.targetId) { if (msg.targetId == this.targetId) {
this.getNewMessage() this.getNewMessage()
} }
}) })
// 清理聊天记录
uni.$once('cleanGroupMessage', this.getMessageList) uni.$once('cleanGroupMessage', this.getMessageList)
}, },
onNavigationBarButtonTap() { onNavigationBarButtonTap() {
@@ -87,6 +102,7 @@
}) })
}, },
methods: { methods: {
// 转到好友资料页面
toUser(item) { toUser(item) {
if (item.senderUserId == '__system__') { if (item.senderUserId == '__system__') {
return return
@@ -106,9 +122,9 @@
this.conversationType, this.conversationType,
this.targetId, this.targetId,
this.latestMessage.sentTime, this.latestMessage.sentTime,
1, 10,
false, false,
(messages) => { (messages) => {
this.messages = this.messages.concat(messages) this.messages = this.messages.concat(messages)
this.scrollBottom() this.scrollBottom()
}) })
@@ -122,7 +138,8 @@
100, 100,
true, true,
(messages) => { (messages) => {
this.messages = messages.reverse() console.log(messages);
this.messages = messages.reverse()
this.scrollBottom() this.scrollBottom()
}) })
}, },
@@ -161,6 +178,14 @@
.cell { .cell {
padding: 10rpx 30rpx; padding: 10rpx 30rpx;
.cell-system {
align-items: center;
.text {
font-size: 24rpx;
color: $text-gray-m;
}
}
.cell-item { .cell-item {
width: 690rpx; width: 690rpx;
justify-content: flex-start; justify-content: flex-start;

View File

@@ -5,8 +5,8 @@
<cell class="cell" v-for="(item, index) in messages" :key="index"> <cell class="cell" v-for="(item, index) in messages" :key="index">
<view class="time"> <view class="time">
<text class="text">{{ customCN(item.sentTime) }}</text> <text class="text">{{ customCN(item.sentTime) }}</text>
</view> </view>
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'"> <view :class="['cell-item', item.messageDirection == 1 ? 'right' : 'left']">
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)" <u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="contact(item.senderUserId).portraitUrl" /> :src="contact(item.senderUserId).portraitUrl" />
<view class="msg"> <view class="msg">