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 @@