成员管理的基础

This commit is contained in:
2022-02-15 10:14:52 +08:00
parent 2122a0b079
commit a831b65a5f
3 changed files with 344 additions and 222 deletions

View File

@@ -117,9 +117,10 @@ const getGroupBase = (groupId) => {
})
}
const getGroupUsers = (groupId) => {
const getGroupUsers = (groupId, limit) => {
limit = limit || 0
return request({
url: 'im/groups/' + groupId + '/users'
url: 'im/groups/' + groupId + '/users?limit=' + limit
})
}
@@ -210,6 +211,59 @@ const dismissGroup = (groupId) => {
})
}
/**
* 移除群成员
*/
const removeGroupUser = (groupId, userId) => {
return request({
method: 'DELETE',
url: 'im/groups/' + groupId + '/users/' + userId
})
}
/**
* 邀请群成员
*/
const inviteGroupUser = (groupId, userIds) => {
return request({
method: 'POST',
url: 'im/groups/' + groupId + '/invite',
data: {
userIds
}
})
}
/**
* 设置群管理
*/
const setGroupAdmin = (groupId, userId) => {
return request({
method: 'POST',
url: 'im/groups/' + groupId + '/admin/' + userId
})
}
/**
* 移除群管理
*/
const removeGroupAdmin = (groupId, userId) => {
return request({
method: 'DELETE',
url: 'im/groups/' + groupId + '/admin/' + userId
})
}
/**
* 转移群主
*/
const transferGroupOwner = (groupId, userId) => {
return request({
method: 'DELETE',
url: 'im/groups/' + groupId + '/owner/' + userId
})
}
export {
getImToken,
deleteFriend,
@@ -235,5 +289,10 @@ export {
joinGroupPre,
joinGroup,
quitGroup,
dismissGroup
dismissGroup,
inviteGroupUser,
removeGroupUser,
setGroupAdmin,
removeGroupAdmin,
transferGroupOwner
}

View File

@@ -2,7 +2,8 @@
<view class="container">
<view class="members u-border-bottom">
<view class="users">
<view class="user" v-for="(item, index) in users" :key="index" @click="toUser(item)"
<view :class="['user', {'active': item.targetId == currentUser.targetId}]"
v-for="(item, index) in users" :key="index" @click="toUser(item)"
@longpress="showUserActionSheet(item)">
<u-avatar size="44" shape="square" :src="item.portraitUrl">
</u-avatar>
@@ -71,7 +72,12 @@
getGroupInfo,
updateGroup,
quitGroup,
dismissGroup
removeGroupUser,
setGroupAdmin,
removeGroupAdmin,
dismissGroup,
transferGroupOwner,
getGroupUsers
} from '@/apis/interfaces/im.js'
import {
uploads
@@ -133,18 +139,23 @@
}
})
this.initData()
this.initUsers()
uni.$on('groupAnnouncementCreated', this.initData)
},
onUnload() {
uni.$off('groupAnnouncementCreated')
},
methods: {
initUsers() {
getGroupUsers(this.targetId, 14).then(res => {
this.users = res
})
},
initData() {
getGroupInfo(this.targetId).then(res => {
this.group = res.group
this.groupName = res.group.name
this.announcement = res.announcement
this.users = res.users
this.members = res.members
this.loaded = true
this.joinTypeMap = res.join_type_map.map(item => {
@@ -191,7 +202,10 @@
}
},
inviteUser() {
uni.showToast({
icon: 'none',
title: '开发中'
})
},
loadMore() {
uni.navigateTo({
@@ -375,11 +389,54 @@
this.showUserAction = false
},
handleUserAction(e) {
switch (e.key) {
case 0:
removeGroupUser(this.targetId, this.currentUser.targetId).then(res => {
uni.showToast({
icon: 'none',
title: e.name
title: '成员移除成功'
})
console.log(e);
}).catch(err => {
uni.showToast({
icon: 'none',
title: err.message
})
}).finally(() => {
this.initUsers()
})
break;
case 1:
setGroupAdmin(this.targetId, this.currentUser.targetId).then(res => {
uni.showToast({
icon: 'none',
title: '设置管理成功'
})
}).catch(err => {
uni.showToast({
icon: 'none',
title: err.message
})
}).finally(() => {
this.initUsers()
})
break;
case 2:
transferGroupOwner(this.targetId, this.currentUser.targetId).then(res => {
uni.showToast({
icon: 'none',
title: '群主转让成功'
})
}).catch(err => {
uni.showToast({
icon: 'none',
title: err.message
})
}).finally(() => {
this.initUsers()
this.initData()
})
break;
}
}
}
}
@@ -415,6 +472,10 @@
justify-content: center;
align-items: center;
&.active {
background-color: $window-color;
}
.name {
color: $text-gray-m;
width: 126rpx;

View File

@@ -4,7 +4,7 @@
<view class="list">
<view class="list-item" @click="updImgs">
<view class="list-item-left"> <span>修改头像</span> </view>
<view class="avatar" >
<view class="avatar">
<image :src="avatar.showPath || require('@/static/user/cover.png')" mode="aspectFill" />
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
</view>
@@ -67,8 +67,10 @@
updImgs(type) {
uni.chooseImage({
crop: {
width: 80,
height: 80
quality: 100,
width: 128,
height: 128,
resize: true
},
success: res => {
let path = res.tempFiles.map((val, index) => {
@@ -80,7 +82,7 @@
uploads(path).then(pathRes => {
this.avatar.path = pathRes.path[0]
this.avatar.showPath = pathRes.url[0]
this.resetUserInfo('avatar',pathRes.url[0])
this.resetUserInfo('avatar', pathRes.url[0])
}).catch(err => {
uni.showToast({
title: err.message,
@@ -93,19 +95,19 @@
})
},
// 修改姓名
blur(e){
blur(e) {
let value = e.detail.value
if(value !== this.nickname){
this.resetUserInfo('nickname',value)
if (value !== this.nickname) {
this.resetUserInfo('nickname', value)
}
},
// 修改头像或昵称
resetUserInfo(key, value) {
let data ={
key:key,
value:value
let data = {
key: key,
value: value
}
resetUserInfo(data).then(res=>{
resetUserInfo(data).then(res => {
uni.showToast({
title: res,
icon: 'none'