refactor(用户组和权限): 权限表格选择权限优化

This commit is contained in:
shiziyuan9527 2021-05-22 10:01:48 +08:00 committed by 刘瑞斌
parent 845a9fe1b3
commit d8612baeb9
4 changed files with 43 additions and 4 deletions

View File

@ -94,6 +94,8 @@ public class UserService {
private UserRoleService userRoleService; private UserRoleService userRoleService;
@Resource @Resource
private ExtUserGroupMapper extUserGroupMapper; private ExtUserGroupMapper extUserGroupMapper;
@Resource
private ProjectMapper projectMapper;
public List<UserDetail> queryTypeByIds(List<String> userIds) { public List<UserDetail> queryTypeByIds(List<String> userIds) {
return extUserMapper.queryTypeByIds(userIds); return extUserMapper.queryTypeByIds(userIds);
@ -468,14 +470,31 @@ public class UserService {
List<Workspace> workspaces = workspaceService.getWorkspaceListByOrgIdAndUserId(sourceId); List<Workspace> workspaces = workspaceService.getWorkspaceListByOrgIdAndUserId(sourceId);
if (workspaces.size() > 0) { if (workspaces.size() > 0) {
user.setLastWorkspaceId(workspaces.get(0).getId()); user.setLastWorkspaceId(workspaces.get(0).getId());
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaces.get(0).getId());
List<Project> projects = projectMapper.selectByExample(projectExample);
if (projects.size() > 0) {
user.setLastProjectId(projects.get(0).getId());
} else {
user.setLastProjectId("");
}
} else { } else {
user.setLastWorkspaceId(""); user.setLastWorkspaceId("");
user.setLastProjectId("");
} }
} }
if (StringUtils.equals("workspace", sign)) { if (StringUtils.equals("workspace", sign)) {
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(sourceId);
List<Project> projects = projectMapper.selectByExample(projectExample);
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId); Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);
user.setLastOrganizationId(workspace.getOrganizationId()); user.setLastOrganizationId(workspace.getOrganizationId());
user.setLastWorkspaceId(sourceId); user.setLastWorkspaceId(sourceId);
if (projects.size() > 0) {
user.setLastProjectId(projects.get(0).getId());
} else {
user.setLastProjectId("");
}
} }
BeanUtils.copyProperties(user, newUser); BeanUtils.copyProperties(user, newUser);
// 切换工作空间或组织之后更新 session 里的 user // 切换工作空间或组织之后更新 session 里的 user

View File

@ -159,7 +159,11 @@ export default {
if (response.data.workspaceId) { if (response.data.workspaceId) {
localStorage.setItem("workspace_id", response.data.workspaceId); localStorage.setItem("workspace_id", response.data.workspaceId);
} }
localStorage.removeItem(PROJECT_ID); if (response.data.lastProjectId) {
localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
} else {
localStorage.removeItem(PROJECT_ID);
}
this.$router.push('/').then(() => { this.$router.push('/').then(() => {
window.location.reload(); window.location.reload();
}).catch(err => err); }).catch(err => err);
@ -173,7 +177,11 @@ export default {
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => { this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
saveLocalStorage(response); saveLocalStorage(response);
localStorage.setItem("workspace_id", workspaceId); localStorage.setItem("workspace_id", workspaceId);
localStorage.removeItem(PROJECT_ID); if (response.data.lastProjectId) {
localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
} else {
localStorage.removeItem(PROJECT_ID);
}
this.$router.push('/').then(() => { this.$router.push('/').then(() => {
window.location.reload(); window.location.reload();
}).catch(err => err); }).catch(err => err);

View File

@ -1,6 +1,6 @@
<template> <template>
<el-dialog :close-on-click-modal="false" :title="title" <el-dialog :close-on-click-modal="false" :title="title"
:visible.sync="createVisible" width="35%" :visible.sync="createVisible" width="40%"
@closed="handleClose" class="edit-user-dialog" @closed="handleClose" class="edit-user-dialog"
:destroy-on-close="true"> :destroy-on-close="true">
<div v-loading="result.loading"> <div v-loading="result.loading">

View File

@ -32,7 +32,19 @@ export default {
}, },
methods: { methods: {
change(val, permission) { change(val, permission) {
permission.checked = val; //
let id = permission.id.split(":")[1];
if (id === "READ" && !val) {
this.permissions.map(p => p.checked = val);
} else {
if (val) {
let p = this.permissions.filter(p => p.id.split(":")[1] === "READ");
if (p.length > 0) {
p[0].checked = val;
}
}
permission.checked = val;
}
} }
} }
} }