From 1b31181a6c3cb1fd38eecf642c6382d5937a422a Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 7 Jun 2021 14:47:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B7=BB=E5=8A=A0=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E3=80=81=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=E3=80=81?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B9=8B=E5=90=8E=E5=88=B7=E6=96=B0=20sessio?= =?UTF-8?q?n=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtUserMapper.java | 2 ++ .../base/mapper/ext/ExtUserMapper.xml | 5 ++++ .../metersphere/service/WorkspaceService.java | 18 +++++------ frontend/src/business/App.vue | 30 +++++++++++++------ .../components/common/head/HeaderOrgWs.vue | 5 ++-- .../organization/OrganizationWorkspace.vue | 4 +-- .../settings/system/Organization.vue | 7 +++-- .../settings/system/SystemWorkspace.vue | 5 +++- .../settings/workspace/MsProject.vue | 4 +-- 9 files changed, 52 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java index 1c03fac0ea..407a1d7bfc 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java @@ -29,4 +29,6 @@ public interface ExtUserMapper { List selectIdsByQuery(@Param("request") UserRequest request); void updateLastProjectIdIfNull(@Param("projectId") String projectId, @Param("userId") String userId); + + void updateLastWorkspaceIdIfNull(@Param("workspaceId") String workspaceId, @Param("userId") String userId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml index 97556c3d12..4fde199ab0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml @@ -107,4 +107,9 @@ update user set last_project_id = #{projectId} where id = #{userId} and (last_project_id is null or last_project_id = '') + + + update user set last_workspace_id = #{workspaceId} where id = #{userId} + and (last_workspace_id is null or last_workspace_id = '') + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index b76140eb79..8f64804efc 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -2,11 +2,11 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; import io.metersphere.base.domain.*; -import io.metersphere.base.mapper.*; -import io.metersphere.base.mapper.ext.ExtOrganizationMapper; -import io.metersphere.base.mapper.ext.ExtUserGroupMapper; -import io.metersphere.base.mapper.ext.ExtUserRoleMapper; -import io.metersphere.base.mapper.ext.ExtWorkspaceMapper; +import io.metersphere.base.mapper.GroupMapper; +import io.metersphere.base.mapper.ProjectMapper; +import io.metersphere.base.mapper.UserGroupMapper; +import io.metersphere.base.mapper.WorkspaceMapper; +import io.metersphere.base.mapper.ext.*; import io.metersphere.commons.constants.UserGroupConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.SessionUtils; @@ -42,8 +42,6 @@ public class WorkspaceService { @Resource private ExtUserRoleMapper extUserRoleMapper; @Resource - private UserRoleMapper userRoleMapper; - @Resource private GroupMapper groupMapper; @Resource private ExtOrganizationMapper extOrganizationMapper; @@ -52,11 +50,11 @@ public class WorkspaceService { @Resource private ProjectMapper projectMapper; @Resource - private UserService userService; - @Resource private UserGroupMapper userGroupMapper; @Resource private ExtUserGroupMapper extUserGroupMapper; + @Resource + private ExtUserMapper extUserMapper; public Workspace saveWorkspace(Workspace workspace) { if (StringUtils.isBlank(workspace.getName())) { @@ -85,6 +83,8 @@ public class WorkspaceService { userGroup.setGroupId(UserGroupConstants.WS_ADMIN); userGroup.setSourceId(workspace.getId()); userGroupMapper.insert(userGroup); + // 新项目创建新工作空间时设置 + extUserMapper.updateLastWorkspaceIdIfNull(workspace.getId(), SessionUtils.getUserId()); } else { workspace.setUpdateTime(currentTime); workspaceMapper.updateByPrimaryKeySelective(workspace); diff --git a/frontend/src/business/App.vue b/frontend/src/business/App.vue index 274b3ac052..d955a309fa 100644 --- a/frontend/src/business/App.vue +++ b/frontend/src/business/App.vue @@ -109,7 +109,7 @@ export default { return { reload: this.reload, reloadTopMenus: this.reloadTopMenus, - } + }; }, methods: { initSessionTimer() { @@ -148,17 +148,29 @@ export default { }, reload() { // 先隐藏 - this.isShow = false + this.isShow = false; this.$nextTick(() => { - this.isShow = true - }) + this.isShow = true; + }); }, reloadTopMenus() { - // 先隐藏 - this.isMenuShow = false - this.$nextTick(() => { - this.isMenuShow = true - }) + this.$get("/isLogin").then(response => { + if (response.data.success) { + this.$setLang(response.data.data.language); + saveLocalStorage(response.data); + // 先隐藏 + this.isMenuShow = false; + this.isShow = false; + this.$nextTick(() => { + this.isShow = true; + this.isMenuShow = true; + }); + } else { + window.location.href = "/login"; + } + }).catch(() => { + window.location.href = "/login"; + }); } }, components: { diff --git a/frontend/src/business/components/common/head/HeaderOrgWs.vue b/frontend/src/business/components/common/head/HeaderOrgWs.vue index cd8d35c8c9..87b61be53c 100644 --- a/frontend/src/business/components/common/head/HeaderOrgWs.vue +++ b/frontend/src/business/components/common/head/HeaderOrgWs.vue @@ -61,8 +61,7 @@