diff --git a/apis/interfaces/im.js b/apis/interfaces/im.js index 2eb828a..ac954f5 100644 --- a/apis/interfaces/im.js +++ b/apis/interfaces/im.js @@ -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 } diff --git a/pages/im/group/info.vue b/pages/im/group/info.vue index 9da3ed2..cfe3242 100644 --- a/pages/im/group/info.vue +++ b/pages/im/group/info.vue @@ -2,7 +2,8 @@ - @@ -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) { - uni.showToast({ - icon: 'none', - title: e.name - }) - console.log(e); + switch (e.key) { + case 0: + removeGroupUser(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 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; diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index 124931b..fa6f7f5 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -1,211 +1,213 @@ - - - - -