成员管理的基础
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
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;
|
||||
|
||||
@@ -1,87 +1,89 @@
|
||||
<template>
|
||||
<view class="setting">
|
||||
<!-- 更多管理 -->
|
||||
<view class="list">
|
||||
<view class="list-item" @click="updImgs">
|
||||
<view class="list-item-left"> <span>修改头像</span> </view>
|
||||
<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>
|
||||
</view>
|
||||
<view class="list-item">
|
||||
<view class="list-item-left"> <span>修改昵称</span> </view>
|
||||
<view class="input">
|
||||
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
|
||||
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-toast ref="uToast" />
|
||||
</view>
|
||||
<view class="setting">
|
||||
<!-- 更多管理 -->
|
||||
<view class="list">
|
||||
<view class="list-item" @click="updImgs">
|
||||
<view class="list-item-left"> <span>修改头像</span> </view>
|
||||
<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>
|
||||
</view>
|
||||
<view class="list-item">
|
||||
<view class="list-item-left"> <span>修改昵称</span> </view>
|
||||
<view class="input">
|
||||
<input type="text" :value="nickname" @blur='blur' placeholder="请输入用户的昵称" maxlength="12" />
|
||||
<u-icon name="arrow-right" color="#999" size="20"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-toast ref="uToast" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getUserSettingInfo,
|
||||
resetUserInfo
|
||||
} from '@/apis/interfaces/setting.js'
|
||||
import {
|
||||
uploads
|
||||
} from '@/apis/interfaces/uploading'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
canLogin: true,
|
||||
nickname: '',
|
||||
avatar: {
|
||||
path: '',
|
||||
showPath: ''
|
||||
},
|
||||
is_bind: true
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.getUserInfo()
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.getUserInfo()
|
||||
},
|
||||
methods: {
|
||||
// 获取当前用户得基本信息
|
||||
getUserInfo() {
|
||||
getUserSettingInfo().then(res => {
|
||||
this.avatar.showPath = res.avatar
|
||||
this.nickname = res.nickname
|
||||
this.is_bind = res.is_bind
|
||||
uni.stopPullDownRefresh()
|
||||
}).catch(err => {
|
||||
this.$refs.uToast.show({
|
||||
title: err.message,
|
||||
type: 'primary',
|
||||
duration: 3000
|
||||
})
|
||||
})
|
||||
},
|
||||
// 上传头像
|
||||
updImgs(type) {
|
||||
uni.chooseImage({
|
||||
crop: {
|
||||
width: 80,
|
||||
height: 80
|
||||
},
|
||||
success: res => {
|
||||
let path = res.tempFiles.map((val, index) => {
|
||||
return {
|
||||
name: 'uploads' + index,
|
||||
uri: val.path
|
||||
}
|
||||
})
|
||||
uploads(path).then(pathRes => {
|
||||
this.avatar.path = pathRes.path[0]
|
||||
this.avatar.showPath = pathRes.url[0]
|
||||
this.resetUserInfo('avatar',pathRes.url[0])
|
||||
}).catch(err => {
|
||||
import {
|
||||
getUserSettingInfo,
|
||||
resetUserInfo
|
||||
} from '@/apis/interfaces/setting.js'
|
||||
import {
|
||||
uploads
|
||||
} from '@/apis/interfaces/uploading'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
canLogin: true,
|
||||
nickname: '',
|
||||
avatar: {
|
||||
path: '',
|
||||
showPath: ''
|
||||
},
|
||||
is_bind: true
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.getUserInfo()
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.getUserInfo()
|
||||
},
|
||||
methods: {
|
||||
// 获取当前用户得基本信息
|
||||
getUserInfo() {
|
||||
getUserSettingInfo().then(res => {
|
||||
this.avatar.showPath = res.avatar
|
||||
this.nickname = res.nickname
|
||||
this.is_bind = res.is_bind
|
||||
uni.stopPullDownRefresh()
|
||||
}).catch(err => {
|
||||
this.$refs.uToast.show({
|
||||
title: err.message,
|
||||
type: 'primary',
|
||||
duration: 3000
|
||||
})
|
||||
})
|
||||
},
|
||||
// 上传头像
|
||||
updImgs(type) {
|
||||
uni.chooseImage({
|
||||
crop: {
|
||||
quality: 100,
|
||||
width: 128,
|
||||
height: 128,
|
||||
resize: true
|
||||
},
|
||||
success: res => {
|
||||
let path = res.tempFiles.map((val, index) => {
|
||||
return {
|
||||
name: 'uploads' + index,
|
||||
uri: val.path
|
||||
}
|
||||
})
|
||||
uploads(path).then(pathRes => {
|
||||
this.avatar.path = pathRes.path[0]
|
||||
this.avatar.showPath = pathRes.url[0]
|
||||
this.resetUserInfo('avatar', pathRes.url[0])
|
||||
}).catch(err => {
|
||||
uni.showToast({
|
||||
title: err.message,
|
||||
icon: "none",
|
||||
@@ -89,29 +91,29 @@
|
||||
mask: true
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 修改姓名
|
||||
blur(e){
|
||||
let value = e.detail.value
|
||||
if(value !== this.nickname){
|
||||
this.resetUserInfo('nickname',value)
|
||||
}
|
||||
},
|
||||
// 修改头像或昵称
|
||||
resetUserInfo(key, value) {
|
||||
let data ={
|
||||
key:key,
|
||||
value:value
|
||||
}
|
||||
resetUserInfo(data).then(res=>{
|
||||
uni.showToast({
|
||||
title: res,
|
||||
icon: 'none'
|
||||
})
|
||||
this.getUserInfo()
|
||||
}).catch(err => {
|
||||
}
|
||||
})
|
||||
},
|
||||
// 修改姓名
|
||||
blur(e) {
|
||||
let value = e.detail.value
|
||||
if (value !== this.nickname) {
|
||||
this.resetUserInfo('nickname', value)
|
||||
}
|
||||
},
|
||||
// 修改头像或昵称
|
||||
resetUserInfo(key, value) {
|
||||
let data = {
|
||||
key: key,
|
||||
value: value
|
||||
}
|
||||
resetUserInfo(data).then(res => {
|
||||
uni.showToast({
|
||||
title: res,
|
||||
icon: 'none'
|
||||
})
|
||||
this.getUserInfo()
|
||||
}).catch(err => {
|
||||
uni.showToast({
|
||||
title: err.message,
|
||||
icon: "none",
|
||||
@@ -119,93 +121,93 @@
|
||||
mask: true
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
page {
|
||||
background-color: #F8F8F8;
|
||||
}
|
||||
page {
|
||||
background-color: #F8F8F8;
|
||||
}
|
||||
|
||||
.setting {
|
||||
position: relative;
|
||||
background-color: #fff;
|
||||
.setting {
|
||||
position: relative;
|
||||
background-color: #fff;
|
||||
|
||||
// 更多管理
|
||||
.list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
top: -10rpx;
|
||||
border-radius: 20rpx;
|
||||
margin: 0 $margin;
|
||||
padding: 30rpx 0;
|
||||
width: calc(100% - 80rpx);
|
||||
// 更多管理
|
||||
.list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
top: -10rpx;
|
||||
border-radius: 20rpx;
|
||||
margin: 0 $margin;
|
||||
padding: 30rpx 0;
|
||||
width: calc(100% - 80rpx);
|
||||
|
||||
.list-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 40rpx 0;
|
||||
border-bottom: solid 1rpx #f9f9f9;
|
||||
box-sizing: border-box;
|
||||
font-size: $title-size;
|
||||
.list-item {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 40rpx 0;
|
||||
border-bottom: solid 1rpx #f9f9f9;
|
||||
box-sizing: border-box;
|
||||
font-size: $title-size;
|
||||
|
||||
.avatar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
.avatar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
|
||||
|
||||
image {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
}
|
||||
image {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
text-align: right;
|
||||
flex: 1;
|
||||
.input {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
text-align: right;
|
||||
flex: 1;
|
||||
|
||||
input {
|
||||
padding-right: $padding - 10;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
input {
|
||||
padding-right: $padding - 10;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.list-item-left {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
box-sizing: border-box;
|
||||
.list-item-left {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
box-sizing: border-box;
|
||||
|
||||
image {
|
||||
width: 40rpx;
|
||||
}
|
||||
image {
|
||||
width: 40rpx;
|
||||
}
|
||||
|
||||
span {
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
span {
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user