工作空间成员列表添加角色列

This commit is contained in:
shiziyuan9527 2020-02-28 15:57:58 +08:00
parent 44743620d4
commit f5a315ffcd
6 changed files with 62 additions and 18 deletions

View File

@ -22,6 +22,8 @@ public interface ExtUserRoleMapper {
List<Role> getOrganizationMemberRoles(@Param("orgId") String orgId, @Param("userId") String userId); List<Role> getOrganizationMemberRoles(@Param("orgId") String orgId, @Param("userId") String userId);
List<Role> getWorkspaceMemberRoles(@Param("workspaceId") String workspaceId, @Param("userId") String userId);
List<User> getBesideOrgMemberList(@Param("orgId") String orgId); List<User> getBesideOrgMemberList(@Param("orgId") String orgId);

View File

@ -80,6 +80,14 @@
where ur.source_id = #{orgId}) where ur.source_id = #{orgId})
</select> </select>
<select id="getWorkspaceMemberRoles" resultType="io.metersphere.base.domain.Role">
select r.id, r.name
from workspace w
join user_role ur on w.id = ur.source_id
join role r on r.id = ur.role_id
where w.id = #{workspaceId} and ur.user_id = #{userId}
</select>
</mapper> </mapper>

View File

@ -16,8 +16,13 @@ public class UserRoleController {
@Resource @Resource
private UserRoleService userRoleService; private UserRoleService userRoleService;
@GetMapping("/list/{orgId}/{userId}") @GetMapping("/list/org/{orgId}/{userId}")
public List<Role> getOrganizationMemberRoles(@PathVariable String orgId, @PathVariable String userId) { public List<Role> getOrganizationMemberRoles(@PathVariable String orgId, @PathVariable String userId) {
return userRoleService.getOrganizationMemberRoles(orgId, userId); return userRoleService.getOrganizationMemberRoles(orgId, userId);
} }
@GetMapping("/list/ws/{workspaceId}/{userId}")
public List<Role> workspaceId(@PathVariable String workspaceId, @PathVariable String userId) {
return userRoleService.getWorkspaceMemberRoles(workspaceId, userId);
}
} }

View File

@ -19,4 +19,8 @@ public class UserRoleService {
return extUserRoleMapper.getOrganizationMemberRoles(orgId, userId); return extUserRoleMapper.getOrganizationMemberRoles(orgId, userId);
} }
public List<Role> getWorkspaceMemberRoles(String workspaceId, String userId) {
return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
}
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-loading="loading"> <div v-loading="result.loading">
<el-card> <el-card>
<div slot="header"> <div slot="header">
<el-row type="flex" justify="space-between" align="middle"> <el-row type="flex" justify="space-between" align="middle">
@ -16,6 +16,13 @@
<el-table-column prop="name" label="用户名"/> <el-table-column prop="name" label="用户名"/>
<el-table-column prop="email" label="邮箱"/> <el-table-column prop="email" label="邮箱"/>
<el-table-column prop="phone" label="电话"/> <el-table-column prop="phone" label="电话"/>
<el-table-column prop="roles" label="角色" width="140">
<template slot-scope="scope">
<el-tag v-for="(role, index) in scope.row.roles" :key="index" size="mini" effect="dark" type="success">
{{ role.name }}
</el-tag>
</template>
</el-table-column>
<el-table-column> <el-table-column>
<template slot-scope="scope"> <template slot-scope="scope">
<el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/> <el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/>
@ -41,7 +48,7 @@
</div> </div>
</el-card> </el-card>
<el-dialog title="添加成员" :visible.sync="createVisible" width="30%"> <el-dialog title="添加成员" :visible.sync="createVisible" width="30%" :destroy-on-close="true" @close="closeFunc">
<el-form :model="form" ref="form" :rules="rules" label-position="left" label-width="100px" size="small"> <el-form :model="form" ref="form" :rules="rules" label-position="left" label-width="100px" size="small">
<el-form-item label="成员" prop="userIds"> <el-form-item label="成员" prop="userIds">
<el-select v-model="form.userIds" multiple placeholder="请选择成员" class="select-width"> <el-select v-model="form.userIds" multiple placeholder="请选择成员" class="select-width">
@ -53,6 +60,16 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="角色" prop="roleIds">
<el-select v-model="form.roleIds" multiple placeholder="请选择角色" class="select-width">
<el-option
v-for="item in form.roles"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button> <el-button type="primary" @click="submitForm('form')" size="medium">保存</el-button>
@ -71,7 +88,7 @@
components: {MsCreateBox}, components: {MsCreateBox},
data() { data() {
return { return {
loading: false, result: {},
form: {}, form: {},
btnTips: "添加成员", btnTips: "添加成员",
createVisible: false, createVisible: false,
@ -81,6 +98,9 @@
rules: { rules: {
userIds: [ userIds: [
{required: true, message: '请选择成员', trigger: ['blur', 'change']} {required: true, message: '请选择成员', trigger: ['blur', 'change']}
],
roleIds: [
{required: true, message: '请选择角色', trigger: ['blur', 'change']}
] ]
}, },
multipleSelection: [], multipleSelection: [],
@ -107,15 +127,17 @@
workspaceId: this.currentUser().lastWorkspaceId workspaceId: this.currentUser().lastWorkspaceId
}; };
this.$post(this.buildPagePath(this.queryPath), param).then(response => { this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
if (response.data.success) { let data = response.data;
let data = response.data.data; this.tableData = data.listObject;
this.total = data.itemCount; let url = "/userrole/list/ws/" + this.currentUser().lastWorkspaceId;
this.tableData = data.listObject; for (let i = 0; i < this.tableData.length; i++) {
} else { this.$get(url + "/" + this.tableData[i].id, response => {
this.$message.error(response.message); let roles = response.data;
this.$set(this.tableData[i], "roles", roles);
})
} }
this.loading = false; this.total = data.itemCount;
}) })
}, },
@ -131,6 +153,10 @@
handleCurrentChange(current) { handleCurrentChange(current) {
this.currentPage = current; this.currentPage = current;
}, },
closeFunc() {
this.form = {};
this.initTableData();
},
del(row) { del(row) {
this.$confirm('移除该成员, 是否继续?', '提示', { this.$confirm('移除该成员, 是否继续?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
@ -171,6 +197,9 @@
message: '获取用户列表失败' message: '获取用户列表失败'
}); });
}); });
this.result = this.$get('/role/list/test', response => {
this.$set(this.form, "roles", response.data);
})
}, },
submitForm(formName) { submitForm(formName) {
this.loading = true; this.loading = true;

View File

@ -22,7 +22,6 @@
{{ role.name }} {{ role.name }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column> <el-table-column>
<template slot-scope="scope"> <template slot-scope="scope">
@ -95,7 +94,7 @@
<el-input v-model="form.phone" autocomplete="off"/> <el-input v-model="form.phone" autocomplete="off"/>
</el-form-item> </el-form-item>
<el-form-item label="角色" prop="roleIds"> <el-form-item label="角色" prop="roleIds">
<el-select v-model="form.roleIds" multiple placeholder="请选择角色" class="select-width" @remove-tag="checkTag" > <el-select v-model="form.roleIds" multiple placeholder="请选择角色" class="select-width">
<el-option <el-option
v-for="item in form.allroles" v-for="item in form.allroles"
:key="item.id" :key="item.id"
@ -159,7 +158,7 @@
this.result = this.$post(this.buildPagePath(this.queryPath), param, response => { this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
let data = response.data; let data = response.data;
this.tableData = data.listObject; this.tableData = data.listObject;
let url = "/userrole/list/" + this.currentUser().lastOrganizationId; let url = "/userrole/list/org/" + this.currentUser().lastOrganizationId;
for (let i = 0; i < this.tableData.length; i++) { for (let i = 0; i < this.tableData.length; i++) {
this.$get(url + "/" + this.tableData[i].id, response => { this.$get(url + "/" + this.tableData[i].id, response => {
let roles = response.data; let roles = response.data;
@ -215,9 +214,6 @@
this.initTableData(); this.initTableData();
}); });
}, },
checkTag() {
// todo
},
del(row) { del(row) {
this.$confirm('是否删除用户 ' + row.name + ' ?', '', { this.$confirm('是否删除用户 ' + row.name + ' ?', '', {
confirmButtonText: '确定', confirmButtonText: '确定',