群邀请成员功能

This commit is contained in:
dong 2023-05-22 11:02:36 +08:00
parent 2635ea8c57
commit 77a80c2b2d
2 changed files with 70 additions and 23 deletions

View File

@ -296,6 +296,15 @@ export default {
return item.leaderId != this.myMemberId;
},
isShow: (item) => item.type === 'GROUP_CHAT'
},
{
label: '邀请成员',
handler: this.groupSet,
groupInfo: item,
isDisabled: (item) => {
return item.leaderId != this.myMemberId;
},
isShow: (item) => item.type === 'GROUP_CHAT'
}
];
this.menu = [];

View File

@ -41,13 +41,13 @@
<b>{{ selectTreeNode.length }}</b>
<b></b>
<div class="tagBox">
<el-tag v-for="(tag, index) in selectTreeNode" :key="index" class="tag" :class="{disableClose: tag.disabled}" :type="tag.disabled ? 'warning' : ''" :closable="!treeDisabled" @close="tagClose(tag)">
<el-tag v-for="(tag, index) in selectTreeNode" :key="index" class="tag" :class="{disableClose: tag.disabled || addDisabledNode(tag)}" :type="tag.disabled ? 'warning' : ''" :closable="!treeDisabled" @close="tagClose(tag)">
{{ tag.labelName }}
</el-tag>
</div>
<el-divider />
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="群名称:" prop="name">
<el-form-item v-if="showFormName" label="群名称:" prop="name">
<el-input v-model="form.name" :disabled="nameDisabled" />
</el-form-item>
<!-- <el-form-item label="群头像:" prop="imageUrl">
@ -69,7 +69,7 @@
</template>
<script>
import { createGroup } from '@/api/newChat';
import { createGroup, inviteMemberToGroup } from '@/api/newChat';
import { getUploadUrl } from '@/api/projectConfig';
export default {
name: 'EditGroup',
@ -93,7 +93,7 @@ export default {
children: 'children',
label: 'labelName',
disabled: (node) => {
if (node.disabled || this.treeDisabled) {
if (node.disabled || this.treeDisabled || this.addDisabledNode(node)) {
return true;
} else {
return false;
@ -104,11 +104,13 @@ export default {
defaultCheckedKeys: [],
selectTreeNode: [],
form: {
id: '',
name: '',
imageUrl: ''
},
treeDisabled: false,
nameDisabled: false,
showFormName: true,
showSubmitBtn: true
};
},
@ -137,11 +139,18 @@ export default {
this.getActiveTrains();
},
title() {
if (this.title == '创建会话群') {
if (this.title == '邀请成员') {
this.showFormName = false;
this.showSubmitBtn = true;
this.treeDisabled = false;
this.nameDisabled = true;
} else if (this.title == '创建会话群') {
this.showFormName = true;
this.showSubmitBtn = true;
this.treeDisabled = false;
this.nameDisabled = false;
} else {
this.showFormName = true;
this.showSubmitBtn = false;
this.treeDisabled = true;
this.nameDisabled = true;
@ -158,15 +167,22 @@ export default {
},
methods: {
addDisabledNode(node) {
let s = false;
if (this.title == '邀请成员' && this.defaultCheckedKeys.includes(node.id)) {
s = true;
}
return s;
},
getImgUrl(url) {
return url ? this.$store.state.user.ossUrl + '/conversationGroup/' + url : '';
},
tagClose(item) {
if (item.disabled) { return; }
const filter = this.selectTreeNode.filter(ii => {
return item != ii;
return item.id != ii.id;
});
this.$refs.tree.setCheckedNodes(filter);
this.$refs.tree.setChecked(item, false);
this.selectTreeNode = filter;
},
getActiveTrains() {
@ -197,22 +213,43 @@ export default {
return (data.labelName.indexOf(value) !== -1 || flag) && driverNoShow;
},
onSubmit() {
const list = [];
this.selectTreeNode.forEach(item => {
list.push(item.id);
});
const params = {
name: this.form.name,
imageUrl: this.form.imageUrl,
memberIds: list
};
createGroup(this.groupId, params).then(res => {
this.initData();
this.handleClose();
this.$message.success('创建会话群成功!');
}).catch(err => {
this.$message.error(`创建会话群失败!${err.message}`);
});
if (this.title == '邀请成员') {
const list = [];
this.selectTreeNode.forEach(item => {
if (!this.defaultCheckedKeys.includes(item.id)) {
list.push(item.id);
}
});
const params = {
id: this.form.id,
memberIds: list
};
inviteMemberToGroup(this.groupId, params).then(res => {
this.initData();
this.handleClose();
this.$message.success('邀请成员成功!');
}).catch(err => {
this.$message.error(`邀请成员失败!${err.message}`);
});
} else if (this.title == '创建会话群') {
const list = [];
this.selectTreeNode.forEach(item => {
list.push(item.id);
});
const params = {
name: this.form.name,
imageUrl: this.form.imageUrl,
memberIds: list
};
createGroup(this.groupId, params).then(res => {
this.initData();
this.handleClose();
this.$message.success('创建会话群成功!');
}).catch(err => {
this.$message.error(`创建会话群失败!${err.message}`);
});
}
},
initData() {
this.$refs.form && this.$refs.form.resetFields();
@ -282,6 +319,7 @@ export default {
},
setInfo(info) {
if (info) {
this.form.id = info.id || '';
this.form.name = info.name || '';
this.form.imageUrl = info.imageUrl || '';
this.defaultCheckedKeys = [];