refactor(用户组): 成员列表优化

This commit is contained in:
shiziyuan9527 2021-06-29 15:51:53 +08:00 committed by 刘瑞斌
parent 255e908b35
commit eefac4f738
6 changed files with 25 additions and 32 deletions

View File

@ -4,7 +4,8 @@
<select id="getGroupList" resultType="io.metersphere.dto.GroupDTO"> <select id="getGroupList" resultType="io.metersphere.dto.GroupDTO">
select *, (select count(distinct user_group.user_id) from user_group where user_group.group_id = temp.id) as memberSize select *,
(select count(distinct ug.user_id) from user_group ug join user on ug.user_id = user.id where ug.group_id = temp.id) as memberSize
from ( from (
select g.*, o.name as scopeName from `group` g, organization o select g.*, o.name as scopeName from `group` g, organization o
<where> <where>
@ -40,7 +41,7 @@
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by
<foreach collection="request.orders" separator="," item="order"> <foreach collection="request.orders" separator="," item="order">
temp.${order.name} ${order.type} temp.${order.name} ${order.type}, temp.name desc
</foreach> </foreach>
</if> </if>
</select> </select>

View File

@ -377,10 +377,6 @@ public class UserService {
MSException.throwException(Translator.get("cannot_delete_current_user")); MSException.throwException(Translator.get("cannot_delete_current_user"));
} }
UserRoleExample example = new UserRoleExample();
example.createCriteria().andUserIdEqualTo(userId);
userRoleMapper.deleteByExample(example);
UserGroupExample userGroupExample = new UserGroupExample(); UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId); userGroupExample.createCriteria().andUserIdEqualTo(userId);
userGroupMapper.deleteByExample(userGroupExample); userGroupMapper.deleteByExample(userGroupExample);

View File

@ -37,7 +37,7 @@ export default {
let validateSelect = (rule, value, callback) => { let validateSelect = (rule, value, callback) => {
let checkNodes = this.$refs.cascadeSelector.getCheckedNodes(true); let checkNodes = this.$refs.cascadeSelector.getCheckedNodes(true);
if (checkNodes.length === 0) { if (checkNodes.length === 0) {
callback(new Error(this.$t('user.select_group'))); callback(new Error(this.$t('user.select_group').toString()));
} }
callback(); callback();
}; };

View File

@ -43,7 +43,7 @@ export default {
let validateSelect = (rule, value, callback) => { let validateSelect = (rule, value, callback) => {
let checkNodes = this.$refs.cascadeSelector.getCheckedNodes(true); let checkNodes = this.$refs.cascadeSelector.getCheckedNodes(true);
if (checkNodes.length === 0) { if (checkNodes.length === 0) {
callback(new Error(this.$t('user.select_project'))); callback(new Error(this.$t('user.select_project').toString()));
} }
callback(); callback();
}; };

View File

@ -1,7 +1,6 @@
<template> <template>
<div> <div>
<el-dialog :close-on-click-modal="false" :visible.sync="visible" width="65%" top="15vh" <el-dialog :close-on-click-modal="false" :visible.sync="visible" width="65%" top="15vh"
:destroy-on-close="true" @close="close" v-loading="result.loading" :destroy-on-close="true" @close="close" v-loading="result.loading"
class="group-member" class="group-member"
> >
@ -13,7 +12,7 @@
<el-table-column prop="email" :label="$t('commons.email')" show-overflow-tooltip/> <el-table-column prop="email" :label="$t('commons.email')" show-overflow-tooltip/>
<el-table-column prop="phone" :label="$t('commons.phone')" show-overflow-tooltip> <el-table-column prop="phone" :label="$t('commons.phone')" show-overflow-tooltip>
<template v-slot="scope"> <template v-slot="scope">
{{scope.row.phone || '-'}} {{ scope.row.phone || '-' }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="typeLabel" v-if="showTypeLabel"> <el-table-column :label="typeLabel" v-if="showTypeLabel">
@ -23,7 +22,7 @@
width="250" width="250"
trigger="click" trigger="click"
> >
<div v-loading="source.loading" style="height: 150px;overflow: auto;"> <div v-loading="sourceResult.loading" style="height: 150px;overflow: auto;">
<el-tag <el-tag
v-for="item in groupSource" v-for="item in groupSource"
:key="item.id" :key="item.id"
@ -55,7 +54,8 @@
</el-dialog> </el-dialog>
<el-dialog :close-on-click-modal="false" :visible.sync="memberVisible" width="45%" <el-dialog :close-on-click-modal="false" :visible.sync="memberVisible" width="45%"
:title="title" :destroy-on-close="true" v-loading="memberResult.loading" @close="memberDialogClose"> :title="title" :destroy-on-close="true" v-loading="memberResult.loading" @close="memberDialogClose">
<el-form ref="memberFrom" label-position="right" :model="form" size="small" :rules="rules" label-width="120px" style="margin-right: 40px;"> <el-form ref="memberFrom" label-position="right" :model="form" size="small" :rules="rules" label-width="120px"
style="margin-right: 40px;">
<el-form-item :label="$t('commons.member')" prop="userIds"> <el-form-item :label="$t('commons.member')" prop="userIds">
<el-select <el-select
v-model="form.userIds" v-model="form.userIds"
@ -119,7 +119,7 @@ export default {
pageSize: 5, pageSize: 5,
total: 0, total: 0,
result: {}, result: {},
source: {}, sourceResult: {},
memberResult: {}, memberResult: {},
group: {}, group: {},
groupSource: [], groupSource: [],
@ -191,12 +191,9 @@ export default {
this.submitType = 'EDIT'; this.submitType = 'EDIT';
this.getUser(); this.getUser();
this.getResource(); this.getResource();
let userId = row.id; this.$get('/user/group/source/' + row.id + "/" + this.group.id, res => {
let groupId = this.group.id;
this.$get('/user/group/source/' + userId + "/" + groupId, res => {
let data = res.data; let data = res.data;
let userIds = []; let userIds = [row.id];
userIds.push(row.id);
let sourceIds = data.map(d => d.id); let sourceIds = data.map(d => d.id);
this.$set(this.form, 'userIds', userIds); this.$set(this.form, 'userIds', userIds);
this.$set(this.form, 'sourceIds', sourceIds); this.$set(this.form, 'sourceIds', sourceIds);
@ -222,7 +219,7 @@ export default {
}) })
}, },
removeMember(row) { removeMember(row) {
this.$confirm(this.$t('member.remove_member'), '', { this.$confirm(this.$t('member.remove_member').toString(), '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
type: 'warning' type: 'warning'
@ -237,9 +234,7 @@ export default {
}, },
getGroupSource(row) { getGroupSource(row) {
this.groupSource = []; this.groupSource = [];
let userId = row.id; this.sourceResult = this.$get('/user/group/source/' + row.id + "/" + this.group.id, res => {
let groupId = this.group.id;
this.source = this.$get('/user/group/source/' + userId + "/" + groupId, res => {
this.groupSource = res.data; this.groupSource = res.data;
}) })
}, },
@ -265,12 +260,10 @@ export default {
}) })
}, },
getResource() { getResource() {
let id = this.group.id; this.memberResult = this.$get('/organization/list/resource/' + this.group.id + "/" + this.group.type, res => {
let type = this.group.type;
this.memberResult = this.$get('/organization/list/resource/' + id + "/" + type, res => {
let data = res.data; let data = res.data;
if (data) { if (data) {
this._setResource(type, data); this._setResource(this.group.type, data);
} }
}) })
}, },
@ -289,9 +282,9 @@ export default {
} }
}, },
memberDialogClose() { memberDialogClose() {
this.form = {};
this.memberVisible = false; this.memberVisible = false;
this.userSelectDisable = false; this.userSelectDisable = false;
this.form = {};
} }
} }
} }
@ -301,6 +294,7 @@ export default {
.group-member >>> .el-dialog__header { .group-member >>> .el-dialog__header {
padding: 0; padding: 0;
} }
.user-select-left { .user-select-left {
float: left; float: left;
} }

View File

@ -2,7 +2,8 @@
<div v-loading="result.loading"> <div v-loading="result.loading">
<el-card> <el-card>
<template v-slot:header> <template v-slot:header>
<ms-table-header :create-permission="['SYSTEM_GROUP:READ+CREATE','ORGANIZATION_GROUP:READ+CREATE']" :condition.sync="condition" @search="initData" @create="create" <ms-table-header :create-permission="['SYSTEM_GROUP:READ+CREATE','ORGANIZATION_GROUP:READ+CREATE']"
:condition.sync="condition" @search="initData" @create="create"
:create-tip="$t('group.create')" :title="$t('group.group_permission')"/> :create-tip="$t('group.create')" :title="$t('group.group_permission')"/>
</template> </template>
@ -111,8 +112,9 @@ export default {
this.result = this.$post("/user/group/get/" + this.currentPage + "/" + this.pageSize, this.condition, res => { this.result = this.$post("/user/group/get/" + this.currentPage + "/" + this.pageSize, this.condition, res => {
let data = res.data; let data = res.data;
if (data) { if (data) {
this.total = data.itemCount; let {itemCount, listObject} = data;
this.groups = data.listObject; this.total = itemCount;
this.groups = listObject;
} }
}); });
}, },
@ -122,7 +124,7 @@ export default {
edit(row) { edit(row) {
if (row.id === "admin") { if (row.id === "admin") {
this.$warning(this.$t('group.admin_not_allow_edit')); this.$warning(this.$t('group.admin_not_allow_edit'));
return ; return;
} }
this.$refs.editUserGroup.open(row, 'edit', this.$t('group.edit')); this.$refs.editUserGroup.open(row, 'edit', this.$t('group.edit'));
}, },
@ -135,7 +137,7 @@ export default {
del(row) { del(row) {
if (row.system) { if (row.system) {
this.$warning(this.$t('group.admin_not_allow_delete')); this.$warning(this.$t('group.admin_not_allow_delete'));
return ; return;
} }
this.$refs.deleteConfirm.open(row); this.$refs.deleteConfirm.open(row);
}, },