切换组织和切换工作空间0.1

This commit is contained in:
shiziyuan9527 2020-02-19 22:40:57 +08:00
parent 2c70faf180
commit fe2e2e3e73
5 changed files with 133 additions and 6 deletions

View File

@ -24,7 +24,7 @@ public class OrganizationController {
public List<Organization> getOrganizationList() { return organizationService.getOrganizationList(); }
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<Organization>> getUserList(@PathVariable int goPage, @PathVariable int pageSize) {
public Pager<List<Organization>> getOrganizationList(@PathVariable int goPage, @PathVariable int pageSize) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, organizationService.getOrganizationList());
}
@ -34,4 +34,9 @@ public class OrganizationController {
@PostMapping("/update")
public void updateOrganization(@RequestBody Organization organization) { organizationService.updateOrganization(organization); }
@GetMapping("/list/userorg/{userId}")
public List<Organization> getOrganizationListByUserId(@PathVariable String userId) {
return organizationService.getOrganizationListByUserId(userId);
}
}

View File

@ -45,4 +45,9 @@ public class WorkspaceController {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList());
}
@GetMapping("/list/userworkspace/{userId}")
public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) {
return workspaceService.getWorkspaceListByUserId(userId);
}
}

View File

@ -1,11 +1,17 @@
package io.metersphere.service;
import io.metersphere.base.domain.Organization;
import io.metersphere.base.domain.OrganizationExample;
import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.dto.UserRoleHelpDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -15,6 +21,10 @@ public class OrganizationService {
@Resource
private OrganizationMapper organizationMapper;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private ExtUserRoleMapper extUserRoleMapper;
public Organization addOrganization(Organization organization) {
long currentTimeMillis = System.currentTimeMillis();
@ -37,4 +47,19 @@ public class OrganizationService {
organization.setUpdateTime(System.currentTimeMillis());
organizationMapper.updateByPrimaryKeySelective(organization);
}
public List<Organization> getOrganizationListByUserId(String userId) {
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
List<String> list = new ArrayList<>();
userRoleHelpList.forEach(r -> {
if (StringUtils.isEmpty(r.getParentId())) {
list.add(r.getSourceId());
} else {
list.add(r.getParentId());
}
});
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andIdIn(list);
return organizationMapper.selectByExample(organizationExample);
}
}

View File

@ -4,8 +4,10 @@ import io.metersphere.base.domain.UserRole;
import io.metersphere.base.domain.Workspace;
import io.metersphere.base.domain.WorkspaceExample;
import io.metersphere.base.mapper.WorkspaceMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils;
@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -22,6 +25,8 @@ import java.util.stream.Collectors;
public class WorkspaceService {
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private ExtUserRoleMapper extUserRoleMapper;
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
@ -73,4 +78,17 @@ public class WorkspaceService {
}
}
public List<Workspace> getWorkspaceListByUserId(String userId) {
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
List<String> workspaceIds = new ArrayList<>();
userRoleHelpList.forEach(r -> {
if (!StringUtils.isEmpty(r.getParentId())) {
workspaceIds.add(r.getSourceId());
}
});
WorkspaceExample workspaceExample = new WorkspaceExample();
workspaceExample.createCriteria().andIdIn(workspaceIds);
return workspaceMapper.selectByExample(workspaceExample);
}
}

View File

@ -2,11 +2,23 @@
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router
menu-trigger="click">
<el-menu-item index="1"><a href="/" style="text-decoration: none;">{{ $t("i18n.home") }}</a></el-menu-item>
<el-submenu index="2" popper-class="submenu" v-permission="['org_admin']">
<el-submenu index="7" popper-class="submenu">
<template slot="title">组织</template>
<label v-for="(item,index) in organizationList" :key="index">
<el-menu-item @click="clickMenu(item)">{{item.name}}
<i class="el-icon-check"
v-if="item.id === currentUserInfo.lastSourceId || item.id === workspaceParentId"></i>
</el-menu-item>
</label>
</el-submenu>
<el-submenu index="2" popper-class="submenu">
<template slot="title">工作空间</template>
<el-menu-item index="2-1">工作空间1</el-menu-item>
<el-menu-item index="2-2">工作空间2</el-menu-item>
<el-menu-item index="2-3">显示全部</el-menu-item>
<label v-for="(item,index) in workspaceList" :key="index">
<el-menu-item @click="clickMenu(item)">
{{item.name}}
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastSourceId"></i>
</el-menu-item>
</label>
</el-submenu>
<el-submenu index="3" popper-class="submenu" v-permission="['test_manager']">
<template slot="title">项目</template>
@ -44,10 +56,68 @@
<script>
import RecentTestPlan from "./testPlan/RecentTestPlan";
import Cookies from "js-cookie";
import {TokenKey} from "../../common/constants";
export default {
name: "MsMenus",
components: {RecentTestPlan}
components: {RecentTestPlan},
created() {
this.initMenuData();
this.getCurrentUserInfo();
},
computed: {
workspaceParentId() {
let result = '';
if (this.workspaceIds.includes(this.currentUserInfo.lastSourceId)) {
let obj = this.workspaceList.filter(r => r.id === this.currentUserInfo.lastSourceId);
if (obj.length > 0) {
result = obj[0].organizationId;
}
}
return result;
}
},
data() {
return {
organizationList: [
{ index: '7-1', name: '组织1'},
],
workspaceList: [
{ index: '2-1', name: '无工作空间'},
],
currentUserInfo: {},
currentUserId: JSON.parse(Cookies.get(TokenKey)).id,
workspaceIds: []
}
},
methods: {
initMenuData() {
this.$get("/organization/list/userorg/" + this.currentUserId,response => {
this.organizationList = response.data;
})
this.$get("/workspace/list/userworkspace/" + this.currentUserId, response => {
this.workspaceList = response.data;
this.workspaceIds = response.data.map(r => r.id);
})
},
getCurrentUserInfo() {
this.$get("/user/info/" + this.currentUserId, response => {
this.currentUserInfo = response.data;
})
},
clickMenu(data) {
if (data.id === this.currentUserInfo.lastSourceId) {
return false;
}
window.console.log(data.id);
let user = {};
user.id = this.currentUserInfo.id;
user.lastSourceId = data.id;
this.$post("/user/update", user);
window.location.reload();
}
}
}
</script>
@ -73,4 +143,8 @@
.el-divider--horizontal {
margin: 0;
}
.el-icon-check {
color: #44b349;
}
</style>