diff --git a/src/api/chat.js b/src/api/chat.js index a561879..564668e 100644 --- a/src/api/chat.js +++ b/src/api/chat.js @@ -29,6 +29,22 @@ export const getGroupFriendListService = (data) => { } ); } + +export const getGroupUsersListService = (data) => { + const params = new URLSearchParams(); + for (let d in data) { + params.append(d, data[d]); + } + // request.headers["Content-Type"] = "application/json"; + request.defaults.headers["token"] = data.token.value; + return request.post('/im/get_group_users_info', params, { + headers: { + 'token': data.token, // 将 token ��换为您的令牌值 + } + } + ); +} + export const getMessageService = (data) => { const params = new URLSearchParams(); for (let d in data) { diff --git a/src/views/Group.vue b/src/views/Group.vue index 105448b..bac2cb1 100644 --- a/src/views/Group.vue +++ b/src/views/Group.vue @@ -7,8 +7,10 @@ import { addDeviceService } from "@/api/device.js"; import {sendMessageService } from "@/api/chat.js"; import {getGroupFriendListService } from "@/api/chat.js"; import {acceptInviteService } from "@/api/user.js"; +import { rejectInviteService } from "@/api/user.js"; import { deleteDeviceService } from "@/api/device.js"; import { getFriendListService } from "@/api/chat.js"; +import { getGroupUsersListService } from "@/api/chat.js"; import { addGroupService} from "@/api/chat.js"; import {DelFGService} from "@/api/user.js"; import { updateDeviceService } from "@/api/device.js"; @@ -22,6 +24,7 @@ export default { FriendsTableIsDisplay:false, tableData: [], group_id:0, + is_del_group_user:false, GroupRequestIsDisplay : false, GroupRequestList:[], tokenData: { @@ -112,6 +115,7 @@ export default { this.FriendsGList = result.data.friends; this.GroupList=result.data.groups; this.FriendsTableIsDisplay = true; + this.is_del_group_user=false; }else{ ElMessage.error("获取好友列表失败"); } @@ -119,6 +123,27 @@ export default { console.log(e); } }, + async displayGroupUsersInfo(index){ + this.group_id = this.tableData[index].ID; + let result ={} + try{ + let req={ + token: this.tokenData.token, + group_id: this.group_id, + } + result = await getGroupUsersListService(req); + if(result.code ===0){ + this.FriendsGList = result.data; + this.FriendsTableIsDisplay = true; + this.is_del_group_user=true; + + }else{ + ElMessage.error("获取群用户列表失败"); + } + }catch(e){ + console.log(e); + } + }, //邀请好友加入群组 async inviteUser(index) { @@ -236,6 +261,33 @@ export default { console.log(e); } }, + async delGroupUser(index){ + var id = this.FriendsGList[index].id; + let req={ + token: localStorage.getItem("token"), + from_user_id: localStorage.getItem("userId"), + to_user_id: id, + group_id: this.group_id, + msg: "踢出群聊", + type: 4, + } + if (id === parseInt(req.userId)){ + ElMessage.error("不能删除自己,若自己要退出,请解散群聊!") + return + } + try { + var d_re = await DelFGService(req); + if (d_re.code == 0) { + //alert("邀请成功"); + ElMessage.success("删除成功"); + } else { + //alert("操作失败"); + ElMessage.error("操作失败:"+d_re.error); + } + } catch (e) { + console.log(e); + } + }, async getIpClient() { try { const response = await axios.get("https://ipinfo.io/json"); @@ -249,7 +301,11 @@ export default { async displayGroupReq(){ let result ={} try{ - result =await getGroupFriendListService(this.tokenData) + let req={ + token:this.tokenData.token, + type:1 + } + result =await getGroupFriendListService(req) if(result.code ===0){ this.GroupRequestList = result.data; this.GroupRequestIsDisplay = true; @@ -295,9 +351,35 @@ export default { id: im_id, from_user_id: localStorage.getItem("userId"), to_user_id: id, + group_id: this.GroupRequestList[index].group_id, msg: "接受加入群组请求", index: 1, - type: 4, + type: 2, + }); + if(result.code ===0){ + ElMessage.success("接受请求成功"); + this.displayGroupReq(); + }else{ + ElMessage.error("接受请求失败"); + } + }catch(e){ + console.log(e); + } + }, + async RefuseFriendsOrGroup(index){ + var id = this.GroupRequestList[index].id; + var im_id = this.GroupRequestList[index].im_id; + let result ={} + try{ + result =await rejectInviteService({ + token: localStorage.getItem("token"), + id: im_id, + from_user_id: localStorage.getItem("userId"), + to_user_id: id, + group_id: this.GroupRequestList[index].group_id, + msg: "接受加入群组请求", + index: 1, + type: 2, }); if(result.code ===0){ ElMessage.success("接受请求成功"); @@ -480,7 +562,7 @@ export default { @@ -503,8 +585,16 @@ export default { type="primary" size="mini" @click.prevent="inviteFriendAddGroup(scope.$index)" + v-if="is_del_group_user === false" >邀请 + 删除 @@ -529,9 +619,9 @@ export default { width="180" >