From d8612baeb93a6723cc9c9e6b2926c2f735a8ea92 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Sat, 22 May 2021 10:01:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E6=88=B7=E7=BB=84=E5=92=8C?= =?UTF-8?q?=E6=9D=83=E9=99=90):=20=E6=9D=83=E9=99=90=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=9D=83=E9=99=90=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/service/UserService.java | 19 +++++++++++++++++++ .../components/common/head/HeaderOrgWs.vue | 12 ++++++++++-- .../components/settings/system/EditUser.vue | 2 +- .../settings/system/group/GroupPermission.vue | 14 +++++++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 529f7859f7..de64137cc2 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -94,6 +94,8 @@ public class UserService { private UserRoleService userRoleService; @Resource private ExtUserGroupMapper extUserGroupMapper; + @Resource + private ProjectMapper projectMapper; public List queryTypeByIds(List userIds) { return extUserMapper.queryTypeByIds(userIds); @@ -468,14 +470,31 @@ public class UserService { List workspaces = workspaceService.getWorkspaceListByOrgIdAndUserId(sourceId); if (workspaces.size() > 0) { user.setLastWorkspaceId(workspaces.get(0).getId()); + ProjectExample projectExample = new ProjectExample(); + projectExample.createCriteria().andWorkspaceIdEqualTo(workspaces.get(0).getId()); + List projects = projectMapper.selectByExample(projectExample); + if (projects.size() > 0) { + user.setLastProjectId(projects.get(0).getId()); + } else { + user.setLastProjectId(""); + } } else { user.setLastWorkspaceId(""); + user.setLastProjectId(""); } } if (StringUtils.equals("workspace", sign)) { + ProjectExample projectExample = new ProjectExample(); + projectExample.createCriteria().andWorkspaceIdEqualTo(sourceId); + List projects = projectMapper.selectByExample(projectExample); Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId); user.setLastOrganizationId(workspace.getOrganizationId()); user.setLastWorkspaceId(sourceId); + if (projects.size() > 0) { + user.setLastProjectId(projects.get(0).getId()); + } else { + user.setLastProjectId(""); + } } BeanUtils.copyProperties(user, newUser); // 切换工作空间或组织之后更新 session 里的 user diff --git a/frontend/src/business/components/common/head/HeaderOrgWs.vue b/frontend/src/business/components/common/head/HeaderOrgWs.vue index fe4bfb2150..b3a025fda3 100644 --- a/frontend/src/business/components/common/head/HeaderOrgWs.vue +++ b/frontend/src/business/components/common/head/HeaderOrgWs.vue @@ -159,7 +159,11 @@ export default { if (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(() => { window.location.reload(); }).catch(err => err); @@ -173,7 +177,11 @@ export default { this.$post("/user/switch/source/ws/" + workspaceId, {}, response => { saveLocalStorage(response); 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(() => { window.location.reload(); }).catch(err => err); diff --git a/frontend/src/business/components/settings/system/EditUser.vue b/frontend/src/business/components/settings/system/EditUser.vue index 30176b33db..8d04cae962 100644 --- a/frontend/src/business/components/settings/system/EditUser.vue +++ b/frontend/src/business/components/settings/system/EditUser.vue @@ -1,6 +1,6 @@