perf: 管理员可以移除全员群人员

This commit is contained in:
kuaifan 2023-03-17 14:23:57 +08:00
parent 5f009ddbee
commit 9ad018744e
2 changed files with 27 additions and 8 deletions

View File

@ -258,9 +258,14 @@ class WebSocketDialog extends AbstractModel
/** @var WebSocketDialogUser $item */ /** @var WebSocketDialogUser $item */
foreach ($list as $item) { foreach ($list as $item) {
if ($checkDelete) { if ($checkDelete) {
if ($type === 'remove' && !in_array(User::userid(), [$this->owner_id, $item->inviter])) { if ($type === 'remove') {
// 移出时:如果是全员群仅允许管理员操作,其他群仅群主或邀请人可以操作
if ($this->group_type === 'all') {
User::auth("admin");
} elseif (!in_array(User::userid(), [$this->owner_id, $item->inviter])) {
throw new ApiException('只有群主或邀请人可以移出成员'); throw new ApiException('只有群主或邀请人可以移出成员');
} }
}
if ($item->userid == $this->owner_id) { if ($item->userid == $this->owner_id) {
throw new ApiException('群主不可' . $typeDesc); throw new ApiException('群主不可' . $typeDesc);
} }

View File

@ -21,9 +21,7 @@
<li v-for="(item, index) in userList" :key="index" @click="openUser(item.userid)"> <li v-for="(item, index) in userList" :key="index" @click="openUser(item.userid)">
<UserAvatar :userid="item.userid" :size="32" showName tooltipDisabled/> <UserAvatar :userid="item.userid" :size="32" showName tooltipDisabled/>
<div v-if="item.userid === dialogData.owner_id" class="user-tag">{{ $L("群主") }}</div> <div v-if="item.userid === dialogData.owner_id" class="user-tag">{{ $L("群主") }}</div>
<div v-else-if="dialogData.owner_id == userId || item.inviter == userId" class="user-exit" @click.stop="onExit(item)"> <div v-else-if="operableExit(item)" class="user-exit" @click.stop="onExit(item)"><Icon type="md-exit"/></div>
<Icon type="md-exit"/>
</div>
</li> </li>
<li v-if="userList.length === 0" class="no"> <li v-if="userList.length === 0" class="no">
<Loading v-if="loadIng > 0"/> <Loading v-if="loadIng > 0"/>
@ -32,7 +30,7 @@
</ul> </ul>
</div> </div>
<div v-if="dialogData.group_type !== 'all'" class="group-info-button"> <div v-if="operableAdd" class="group-info-button">
<Button v-if="dialogData.owner_id == userId || dialogData.owner_id == 0" @click="openAdd" type="primary" icon="md-add">{{ $L("添加成员") }}</Button> <Button v-if="dialogData.owner_id == userId || dialogData.owner_id == 0" @click="openAdd" type="primary" icon="md-add">{{ $L("添加成员") }}</Button>
</div> </div>
@ -88,7 +86,7 @@ export default {
}, },
computed: { computed: {
...mapState(['cacheDialogs', 'cacheUserBasic']), ...mapState(['cacheDialogs', 'cacheUserBasic', 'userIsAdmin']),
dialogData() { dialogData() {
return this.cacheDialogs.find(({id}) => id == this.dialogId) || {}; return this.cacheDialogs.find(({id}) => id == this.dialogId) || {};
@ -183,6 +181,14 @@ export default {
}); });
}, },
operableAdd() {
const {owner_id, group_type} = this.dialogData
if (group_type == 'all') {
return this.userIsAdmin
}
return [0, this.userId].includes(owner_id)
},
openAdd() { openAdd() {
this.addData = { this.addData = {
dialog_id: this.dialogId, dialog_id: this.dialogId,
@ -209,10 +215,18 @@ export default {
}); });
}, },
operableExit(item) {
const {owner_id, group_type} = this.dialogData
if (group_type == 'all') {
return this.userIsAdmin
}
return owner_id == this.userId || item.inviter == this.userId
},
onExit(item) { onExit(item) {
let content = "你确定要退出群组吗?" let content = "你确定要退出群组吗?"
let userids = []; let userids = [];
if ($A.isJson(item)) { if ($A.isJson(item) && item.userid != this.userId) {
content = `你确定要将【${item.nickname}】移出群组吗?` content = `你确定要将【${item.nickname}】移出群组吗?`
userids = [item.userid]; userids = [item.userid];
} }