refactor: 添加组织、工作空间、项目之后刷新 session user

This commit is contained in:
Captain.B 2021-06-07 14:47:32 +08:00 committed by 刘瑞斌
parent db39402603
commit 1b31181a6c
9 changed files with 52 additions and 28 deletions

View File

@ -29,4 +29,6 @@ public interface ExtUserMapper {
List<String> selectIdsByQuery(@Param("request") UserRequest request); List<String> selectIdsByQuery(@Param("request") UserRequest request);
void updateLastProjectIdIfNull(@Param("projectId") String projectId, @Param("userId") String userId); void updateLastProjectIdIfNull(@Param("projectId") String projectId, @Param("userId") String userId);
void updateLastWorkspaceIdIfNull(@Param("workspaceId") String workspaceId, @Param("userId") String userId);
} }

View File

@ -107,4 +107,9 @@
update user set last_project_id = #{projectId} where id = #{userId} update user set last_project_id = #{projectId} where id = #{userId}
and (last_project_id is null or last_project_id = '') and (last_project_id is null or last_project_id = '')
</update> </update>
<update id="updateLastWorkspaceIdIfNull">
update user set last_workspace_id = #{workspaceId} where id = #{userId}
and (last_workspace_id is null or last_workspace_id = '')
</update>
</mapper> </mapper>

View File

@ -2,11 +2,11 @@ package io.metersphere.service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.GroupMapper;
import io.metersphere.base.mapper.ext.ExtOrganizationMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper; import io.metersphere.base.mapper.UserGroupMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper; import io.metersphere.base.mapper.WorkspaceMapper;
import io.metersphere.base.mapper.ext.ExtWorkspaceMapper; import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.UserGroupConstants; import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
@ -42,8 +42,6 @@ public class WorkspaceService {
@Resource @Resource
private ExtUserRoleMapper extUserRoleMapper; private ExtUserRoleMapper extUserRoleMapper;
@Resource @Resource
private UserRoleMapper userRoleMapper;
@Resource
private GroupMapper groupMapper; private GroupMapper groupMapper;
@Resource @Resource
private ExtOrganizationMapper extOrganizationMapper; private ExtOrganizationMapper extOrganizationMapper;
@ -52,11 +50,11 @@ public class WorkspaceService {
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Resource @Resource
private UserService userService;
@Resource
private UserGroupMapper userGroupMapper; private UserGroupMapper userGroupMapper;
@Resource @Resource
private ExtUserGroupMapper extUserGroupMapper; private ExtUserGroupMapper extUserGroupMapper;
@Resource
private ExtUserMapper extUserMapper;
public Workspace saveWorkspace(Workspace workspace) { public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) { if (StringUtils.isBlank(workspace.getName())) {
@ -85,6 +83,8 @@ public class WorkspaceService {
userGroup.setGroupId(UserGroupConstants.WS_ADMIN); userGroup.setGroupId(UserGroupConstants.WS_ADMIN);
userGroup.setSourceId(workspace.getId()); userGroup.setSourceId(workspace.getId());
userGroupMapper.insert(userGroup); userGroupMapper.insert(userGroup);
// 新项目创建新工作空间时设置
extUserMapper.updateLastWorkspaceIdIfNull(workspace.getId(), SessionUtils.getUserId());
} else { } else {
workspace.setUpdateTime(currentTime); workspace.setUpdateTime(currentTime);
workspaceMapper.updateByPrimaryKeySelective(workspace); workspaceMapper.updateByPrimaryKeySelective(workspace);

View File

@ -109,7 +109,7 @@ export default {
return { return {
reload: this.reload, reload: this.reload,
reloadTopMenus: this.reloadTopMenus, reloadTopMenus: this.reloadTopMenus,
} };
}, },
methods: { methods: {
initSessionTimer() { initSessionTimer() {
@ -148,17 +148,29 @@ export default {
}, },
reload() { reload() {
// //
this.isShow = false this.isShow = false;
this.$nextTick(() => { this.$nextTick(() => {
this.isShow = true this.isShow = true;
}) });
}, },
reloadTopMenus() { reloadTopMenus() {
this.$get("/isLogin").then(response => {
if (response.data.success) {
this.$setLang(response.data.data.language);
saveLocalStorage(response.data);
// //
this.isMenuShow = false this.isMenuShow = false;
this.isShow = false;
this.$nextTick(() => { this.$nextTick(() => {
this.isMenuShow = true this.isShow = true;
}) this.isMenuShow = true;
});
} else {
window.location.href = "/login";
}
}).catch(() => {
window.location.href = "/login";
});
} }
}, },
components: { components: {

View File

@ -61,8 +61,7 @@
</template> </template>
<script> <script>
import {WORKSPACE_ID} from '../../../../common/js/constants'; import {getCurrentUser, saveLocalStorage} from "@/common/js/utils";
import {getCurrentUser, saveLocalStorage} from "../../../../common/js/utils";
export default { export default {
name: "MsHeaderOrgWs", name: "MsHeaderOrgWs",
@ -71,7 +70,7 @@ export default {
this.getCurrentUserInfo(); this.getCurrentUserInfo();
}, },
inject: [ inject: [
'reloadTopMenus' 'reloadTopMenus',
], ],
data() { data() {
return { return {

View File

@ -233,7 +233,7 @@ export default {
} }
}, },
inject: [ inject: [
'reload' 'reloadTopMenus',
], ],
methods: { methods: {
create() { create() {
@ -252,7 +252,7 @@ export default {
this.dialogWsUpdateVisible = false; this.dialogWsUpdateVisible = false;
if (saveType == 'add') { if (saveType == 'add') {
Message.success(this.$t('commons.save_success')); Message.success(this.$t('commons.save_success'));
this.reload(); this.reloadTopMenus();
} else if (saveType == 'update') { } else if (saveType == 'update') {
Message.success(this.$t('commons.modify_success')); Message.success(this.$t('commons.modify_success'));
this.list(); this.list();

View File

@ -227,6 +227,9 @@ export default {
return getCurrentOrganizationId(); return getCurrentOrganizationId();
} }
}, },
inject: [
'reloadTopMenus',
],
data() { data() {
return { return {
queryPath: '/organization/list', queryPath: '/organization/list',
@ -384,7 +387,7 @@ export default {
refreshSessionAndCookies(DEFAULT, sourceId); refreshSessionAndCookies(DEFAULT, sourceId);
} }
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.initTableData(); this.reloadTopMenus();
}); });
}).catch(() => { }).catch(() => {
this.$message({ this.$message({
@ -418,7 +421,7 @@ export default {
if (valid) { if (valid) {
this.result = this.$post(this.createPath, this.form, () => { this.result = this.$post(this.createPath, this.form, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.initTableData(); this.reloadTopMenus();
this.dialogOrgAddVisible = false; this.dialogOrgAddVisible = false;
}); });
} else { } else {

View File

@ -242,6 +242,9 @@ export default {
activated() { activated() {
this.list(); this.list();
}, },
inject: [
'reloadTopMenus',
],
methods: { methods: {
create() { create() {
this.dialogWsAddVisible = true; this.dialogWsAddVisible = true;
@ -271,7 +274,7 @@ export default {
} }
this.result = this.$post("/workspace/" + saveType, this.form, () => { this.result = this.$post("/workspace/" + saveType, this.form, () => {
this.dialogWsAddVisible = false; this.dialogWsAddVisible = false;
this.list(); this.reloadTopMenus();
Message.success(this.$t('commons.save_success')); Message.success(this.$t('commons.save_success'));
}); });
} else { } else {

View File

@ -299,7 +299,7 @@ export default {
MsContainer, MsTableOperator, MsCreateBox, MsTablePagination, MsTableHeader, MsDialogFooter MsContainer, MsTableOperator, MsCreateBox, MsTablePagination, MsTableHeader, MsDialogFooter
}, },
inject: [ inject: [
'reload' 'reloadTopMenus'
], ],
data() { data() {
return { return {
@ -434,7 +434,7 @@ export default {
this.createVisible = false; this.createVisible = false;
Message.success(this.$t('commons.save_success')); Message.success(this.$t('commons.save_success'));
if (saveType === 'add') { if (saveType === 'add') {
this.reload(); this.reloadTopMenus();
} else { } else {
this.list(); this.list();
} }