This commit is contained in:
2022-02-16 18:03:54 +08:00
14 changed files with 149 additions and 138 deletions

View File

@@ -1,15 +1,15 @@
<template>
<view class="members">
<view class="member--list">
<view class="users">
<view :class="['user', {'active': item.targetId == currentUser.targetId}]" @longpress="showAction(item)"
v-for="(item, index) in users" :key="index" @click="toUser(item)">
<u-avatar size="44" shape="square" :src="item.portraitUrl"></u-avatar>
<u-avatar :size="avatarSize" shape="square" :src="contact(item.targetId).portraitUrl"></u-avatar>
<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 class="user" v-if="isAdmin">
<u-avatar @click="inviteUser" size="44" shape="square" icon="plus" bg-color="#eeeeee" color="#999999">
<u-avatar @click="inviteUser" shape="square" icon="plus" bg-color="#eeeeee" color="#999999">
</u-avatar>
<view class="name">邀请好友</view>
</view>
@@ -49,14 +49,26 @@
return {
users: [],
isOwner: false,
isAdmin: false,
isAdmin: false,
adminUid: 0,
members: 0,
actionShow: false,
actionMap: [],
actionTitle: '',
currentUser: {}
currentUser: {},
avatarSize: 40
}
},
computed: {
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
}
},
created() {
this.avatarSize = 126 / 750 * wx.getSystemInfoSync().windowWidth
console.log(this.avatarSize)
},
mounted() {
this.initGroupInfo()
@@ -66,7 +78,7 @@
initGroupInfo() {
getGroupBase(this.targetId).then(res => {
this.isOwner = res.is_owner
this.isAdmin = res.is_admin
this.isAdmin = res.is_admin
this.adminUid = res.user_id
this.members = res.members
})
@@ -79,8 +91,6 @@
},
hideAction(item) {
this.actionShow = false
this.actionTitle = ''
this.currentUser = {}
},
showAction(item) {
this.currentUser = item
@@ -180,6 +190,7 @@
content: '这个操作不可逆转,确定要转让群主身份么?',
success: (res) => {
if (res.confirm) {
console.log(this.targetId, this.currentUser.targetId);
transferGroupOwner(this.targetId, this.currentUser.targetId).then(
res => {
uni.showToast({
@@ -228,73 +239,70 @@
<style lang="scss" scoped>
.members {
.users {
flex-direction: row;
flex-wrap: wrap;
display: flex;
padding: 20rpx 0;
.users {
flex-direction: row;
flex-wrap: wrap;
.user {
overflow: hidden;
position: relative;
width: 126rpx;
margin-left: 20rpx;
margin-bottom: 20rpx;
display: flex;
padding: 20rpx 0;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 0 10rpx 0 0;
.user {
overflow: hidden;
position: relative;
&.active {
background-color: $window-color;
}
.name {
color: $text-gray-m;
width: 126rpx;
margin-left: 20rpx;
margin-bottom: 20rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 0 10rpx 0 0;
text-align: center;
font-size: 26rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-break: break-word;
}
&.active {
background-color: $window-color;
}
.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;
}
.name {
color: $text-gray-m;
width: 126rpx;
text-align: center;
font-size: 26rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
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;
}
.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;
}
}
}
.loadmore {
font-size: 26rpx;
color: $text-gray-m;
text-align: center;
}
.loadmore {
font-size: 26rpx;
color: $text-gray-m;
text-align: center;
}
</style>

View File

@@ -64,7 +64,7 @@
}
},
computed: {
user() {
sender() {
return this.$store.getters.sender
}
},
@@ -87,8 +87,7 @@
sourceType: ['album'],
success: res => {
im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0],
this.user, (
res) => {
this.sender, (res) => {
this.success()
})
}
@@ -99,8 +98,7 @@
sourceType: ['camera'],
success: res => {
im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0],
this.user, (
res) => {
this.sender, (res) => {
this.success()
})
}

View File

@@ -29,7 +29,7 @@
disabled() {
return this.inputTxt.length === 0
},
user() {
sender() {
return this.$store.getters.sender
}
},
@@ -50,7 +50,7 @@
sent() {
if (!this.disabled) {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
im.sentText(this.conversationType, this.targetId, this.inputTxt, this.user, () => {
im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => {
this.$emit('success')
this.inputTxt = ''
})

View File

@@ -36,7 +36,7 @@
}
},
computed: {
user() {
sender() {
return this.$store.getters.sender
}
},
@@ -85,8 +85,7 @@
// 监听录音结束
this.recorderManager.onStop(res => {
im.sentVoice(this.conversationType, this.targetId, res.tempFilePath, (this.maxRecordTime -
this
.recordTime), this.user, () => {
this.recordTime), this.sender, () => {
setTimeout(() => {
this.$emit('success')
}, 500)

View File

@@ -56,13 +56,7 @@
onLoad() {
this.getFriendList()
this.checkNewFriendPending()
uni.$on('onContactNotification', () => {
this.checkNewFriendPending()
this.getFriendList()
})
},
onUnload() {
uni.$off('onContactNotification')
uni.$on('onContactNotification', this.checkNewFriendPending)
},
methods: {
getFriendList() {
@@ -82,11 +76,11 @@
})
},
toGroup() {
uni.navigateTo({
url: '/pages/im/group/index',
fail(err) {
console.log(err);
}
uni.navigateTo({
url: '/pages/im/group/index',
fail(err) {
console.log(err);
}
})
},
toFriend(targetId) {

View File

@@ -29,9 +29,6 @@
this.getPendingList()
uni.$on('onContactNotification', this.getPendingList)
},
onUnload() {
uni.$off('onContactNotification')
},
methods: {
getPendingList() {
im.getPendingList((pendings) => {

View File

@@ -4,8 +4,7 @@
<cell class="cell" v-for="(item, index) in messages" :key="index">
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
<u-avatar class="avatar" @click="toUser(item)" size="36" shape="square"
:src="contact(item.senderUserId).portraitUrl" />
<!-- item.content.userInfo.portraitUrl -->
:src="contact(item.senderUserId).portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" :name="contact(item.senderUserId).name" />
@@ -54,18 +53,18 @@
},
computed: {
latestMessage() {
if (this.messages.length > 1) {
if (this.messages.length) {
return this.messages[this.messages.length - 1]
} else {
return {
sentTime: 0
}
}
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
}
},
onLoad(e) {
@@ -109,7 +108,7 @@
this.latestMessage.sentTime,
1,
false,
(messages) => {
(messages) => {
this.messages = this.messages.concat(messages)
this.scrollBottom()
})
@@ -123,7 +122,7 @@
100,
true,
(messages) => {
this.messages = messages.reverse()
this.messages = messages.reverse()
this.scrollBottom()
})
},

View File

@@ -17,8 +17,8 @@
<u-cell-group class="cells" v-if="group.is_admin">
<u-cell isLink title="修改群聊名称" :value="groupName" @click="onGroupName"></u-cell>
<u-cell isLink title="修改群头像">
<u-avatar slot="value" size="25" shape="square" @click="onGroupAvatar" :src="group.cover"></u-avatar>
<u-cell isLink title="修改群头像" @click="onGroupAvatar">
<u-avatar slot="value" size="25" shape="square" :src="group.cover"></u-avatar>
</u-cell>
<u-cell isLink v-if="group.is_owner" title="准入方式" :value="joinType" @click="onChangeJoinType"></u-cell>
</u-cell-group>

View File

@@ -53,16 +53,20 @@
},
onLoad() {
// 好友申请数量
this.checkNewFriendPending()
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
this.checkNewFriendPending()
// 监听新的好友申请
uni.$on('onContactNotification', () => {
console.log('监听申请');
this.checkNewFriendPending()
})
uni.$on('onContactNotification', this.checkNewFriendPending)
},
onShow() {
if (this.$store.state.token !== '') {
this.getConversationList()
}
uni.$on('onConnectionStatusChange', (status) => {
this.connection = status
})
// 监听新消息
uni.$on('onReceiveMessage', (msg) => {
this.getConversationList()
@@ -73,7 +77,9 @@
},
methods: {
checkNewFriendPending() {
im.getPendingList((pendings) => {
console.log('触发新申请好友事件');
im.getPendingList((pendings) => {
console.log(pendings);
this.hasNewFriends = pendings.length
})
},
@@ -91,7 +97,7 @@
const count = 1000
const timestamp = 0
RongIMLib.getConversationList([1, 3], count, timestamp, (res) => {
if (res.code === 0) {
if (res.code === 0) {
this.conversations = res.conversations
}
})

View File

@@ -8,7 +8,7 @@
</view>
<view class="cell-item" :class="item.messageDirection == 1 ? 'right' : 'left'">
<u-avatar class="avatar" size="36" shape="square" @click="showUser(targetId, item.messageDirection)"
:src="userInfo.portraitUrl" />
:src="contact(item.senderUserId).portraitUrl" />
<view class="msg">
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
:msg="item.content" />
@@ -62,13 +62,18 @@
},
computed: {
latestMessage() {
if (this.messages.length > 1) {
if (this.messages.length) {
return this.messages[this.messages.length - 1]
} else {
return {
sentTime: 0
}
}
},
contact() {
return function(targetId) {
return this.$store.getters.contactInfo(targetId)
}
}
},
onLoad(e) {
@@ -113,6 +118,7 @@
1,
false,
(messages) => {
console.log(messages);
this.messages = this.messages.concat(messages)
this.scrollBottom()
})
@@ -125,7 +131,8 @@
0,
100,
true,
(messages) => {
(messages) => {
console.log(messages);
this.messages = messages.reverse()
this.scrollBottom()
})

View File

@@ -109,8 +109,7 @@ class userAuth {
.access_token)
// 在这里登录成功链接IM服务
getImToken().then(res => {
console.log('在这获取IM-TOKEN', res);
im.connect(res.token, res.userInfo)
im.connect(res.token, res.userInfo, () => {})
})
resolve()
}).catch(err => {

View File

@@ -11,7 +11,7 @@ export default {
},
contactInfo: (state) => (targetId) => {
if (state.contacts[targetId]) {
const info = state.contacts[targetId]
const info = state.contacts[targetId]
return {
name: info.name,
hash: info.hash,
@@ -21,7 +21,7 @@ export default {
return {
name: '',
hash: '',
portraitUrl: ''
portraitUrl: require('@/static/user/cover.png')
}
}
},
@@ -34,7 +34,7 @@ export default {
}
},
mutations: {
updateContactInfo(state, contactInfo) {
updateContactInfo(state, contactInfo) {
Vue.set(state.contacts, contactInfo.targetId, contactInfo)
},
setSenderInfo(state, contactInfo) {
@@ -68,7 +68,6 @@ export default {
// 没有数据,直接新增一条
dispatch('initContact', contactInfo)
} else if (contactInfo.hash != result[0].hash) {
commit('updateContactInfo', contactInfo)
if (contactInfo.portraitUrl && contactInfo.portraitUrl != result[0].portraitUrl) {
saveAvatar(contactInfo, (savedFilePath) => {
const info = {
@@ -79,8 +78,8 @@ export default {
localAvatar: savedFilePath
}
model.update('targetId="' + contactInfo.targetId + '"', info, (err,
res) => {
console.log('UPDATE AVATAR, ERR', err);
res) => {
console.log('UPDATE AVATAR, ERR', err, info);
})
commit('updateContactInfo', info)
})
@@ -93,8 +92,9 @@ export default {
localAvatar: result[0].localAvatar
}
model.update('targetId="' + contactInfo.targetId + '"', info, (err, res) => {
console.log('UPDATE NAME, ERR', err);
console.log('UPDATE NAME, ERR', err, info);
})
commit('updateContactInfo', info)
}
} else {
console.log('updateContact, 无操作');

View File

@@ -71,14 +71,14 @@ const connect = (token, userInfo, callback) => {
})
})
},
fail: () => {
fail: () => {
// 程序是首次运行,初始化加载好友和群组信息
Promise.all([getFriends(), getMyGroups()]).then(result => {
Promise.all([getFriends(), getMyGroups()]).then(result => {
result.map(contacts => {
contacts.map(item => {
store.dispatch('initContact', item)
})
})
})
uni.setStorageSync(FK, userInfo.targetId)
})
}
@@ -141,16 +141,17 @@ const addListeners = () => {
}).catch(err => {
console.log('ERR', err)
})
}
if (!store.getters.contactIsExist(message.senderUserId)) {
getUserInfo(message.senderUserId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.log('ERR', err)
})
}
if (!store.getters.contactIsExist(message.senderUserId)) {
getUserInfo(message.senderUserId).then(res => {
store.dispatch('initContact', res)
}).catch(err => {
console.log('ERR', err)
})
}
newMessage(message)
} else if (message.objectName === RongIMLib.ObjectName.ProfileNotification) {
// 更新会话信息
store.dispatch('updateContact', JSON.parse(message.content.data))
// 调用完更新之后,删除这条消息
RongIMLib.deleteMessagesByIds([message.messageId], ({
@@ -158,7 +159,8 @@ const addListeners = () => {
}) => {
console.log('消息删除结果', code)
})
} else if (message.objectName === RongIMLib.ObjectName.ContactNotification) {
} else if (message.objectName === RongIMLib.ObjectName.ContactNotification) {
console.log('onContactNotification');
// 触发一个新好友的通知事件
uni.$emit('onContactNotification', message.content)
}

View File

@@ -151,14 +151,15 @@ const sentImage = (conversationType, targetId, imageUrl, user, callback) => {
})
}
const sentGif = (conversationType, targetId, gifUrl, time, callback) => {
const sentGif = (conversationType, targetId, gifUrl, time, user, callback) => {
const msg = {
conversationType: conversationType,
targetId: String(targetId),
content: {
objectName: 'RC:GIFMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(gifUrl),
duration: time
duration: time,
userInfo: user
}
}
RongIMLib.sendMediaMessage(msg, {
@@ -177,14 +178,15 @@ const sentGif = (conversationType, targetId, gifUrl, time, callback) => {
})
}
const sendFile = (conversationType, targetId, fileUrl, time, callback) => {
const sendFile = (conversationType, targetId, fileUrl, time, user, callback) => {
const msg = {
conversationType: conversationType,
targetId: String(targetId),
content: {
objectName: 'RC:FileMsg',
local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl),
duration: time
duration: time,
userInfo: user
}
}
RongIMLib.sendMediaMessage(msg, {
@@ -204,7 +206,7 @@ const sendFile = (conversationType, targetId, fileUrl, time, callback) => {
}
export default {
getMessageList,
getMessageList,
getPendingList,
sentText,
sentVoice,