refactor: 使用前端session来保存当前项目、工作空间、组织的信息,切换后可以在不同的页面使用

This commit is contained in:
Captain.B 2021-06-10 19:06:07 +08:00 committed by 刘瑞斌
parent 6a0561462e
commit 9bae1ef89e
32 changed files with 116 additions and 111 deletions

View File

@ -49,7 +49,6 @@ public class APIReportController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APIReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiReportService.list(request));
}

View File

@ -36,7 +36,6 @@ public class APIScenarioReportController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APIScenarioReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiReportService.list(request));
}

View File

@ -82,8 +82,6 @@ public class APITestController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APITestResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPITestRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(SessionUtils.getCurrentProjectId());
return PageUtils.setPageInfo(page, apiTestService.list(request));
}

View File

@ -53,7 +53,7 @@ public class ApiAutomationController {
}});
}
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiAutomationService.list(request));
}
@ -80,7 +80,6 @@ public class ApiAutomationController {
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<ApiScenarioDTO> list(@PathVariable String projectId) {
ApiScenarioRequest request = new ApiScenarioRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(projectId);
return apiAutomationService.list(request);
}

View File

@ -64,21 +64,18 @@ public class ApiDefinitionController {
@RequiresPermissions("PROJECT_API_DEFINITION:READ")
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
}
@PostMapping("/list/relevance/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> listRelevance(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.listRelevance(request));
}
@PostMapping("/list/relevance/review/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> listRelevanceReview(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.listRelevanceReview(request));
}

View File

@ -8,15 +8,11 @@ import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiTestCase;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.service.TestPlanApiCaseService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -35,14 +31,12 @@ public class ApiTestCaseController {
@PostMapping("/list")
public List<ApiTestCaseResult> list(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return apiTestCaseService.list(request);
}
@GetMapping("/findById/{id}")
public ApiTestCaseResult single(@PathVariable String id) {
ApiTestCaseRequest request = new ApiTestCaseRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setId(id);
List<ApiTestCaseResult> list = apiTestCaseService.list(request);
if (!list.isEmpty()) {
@ -62,28 +56,24 @@ public class ApiTestCaseController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ApiTestCaseDTO>> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request));
}
@GetMapping("/list/{projectId}")
public List<ApiTestCaseDTO> list(@PathVariable String projectId) {
ApiTestCaseRequest request = new ApiTestCaseRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(projectId);
return apiTestCaseService.listSimple(request);
}
@PostMapping("/get/request")
public Map<String, String> listSimple(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return apiTestCaseService.getRequest(request);
}
@PostMapping("/get/caseBLOBs/request")
public List<ApiTestCaseInfo> getCaseBLOBs(@RequestBody ApiTestCaseRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
List<ApiTestCaseInfo> returnList = apiTestCaseService.findApiTestCaseBLOBs(request);
return returnList;
}

View File

@ -49,13 +49,11 @@ public class APIReportService {
public List<APIReportResult> list(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestReportMapper.list(request);
}
public List<APIReportResult> recentTest(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestReportMapper.list(request);
}

View File

@ -77,7 +77,6 @@ public class APITestService {
public List<APITestResult> recentTest(QueryAPITestRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extApiTestMapper.list(request);
}
@ -412,8 +411,8 @@ public class APITestService {
ApiTestExample example = new ApiTestExample();
ApiTestExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(resourceIds);
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
if (StringUtils.isNotBlank(request.getProjectId())) {
criteria.andProjectIdEqualTo(request.getProjectId());
}
List<ApiTest> apiTests = apiTestMapper.selectByExample(example);
Map<String, String> apiTestMap = apiTests.stream().collect(Collectors.toMap(ApiTest::getId, ApiTest::getName));

View File

@ -87,7 +87,6 @@ public class ProjectController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ProjectDTO>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ProjectRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
if (StringUtils.isBlank(request.getProjectId())) {
List<String> sourceIds = SessionUtils.getUser().getUserGroups().stream().map(UserGroup::getSourceId).collect(Collectors.toList());
request.setFilters(new HashMap<String, List<String>>() {{
@ -106,7 +105,6 @@ public class ProjectController {
*/
@PostMapping("/list/related")
public List<ProjectDTO> getUserProject(@RequestBody ProjectRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return projectService.getUserProject(request);
}

View File

@ -32,8 +32,7 @@ public class WorkspaceController {
@PostMapping("add")
@MsAuditLog(module = "system_workspace", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#workspace.id)", msClass = WorkspaceService.class)
public Workspace addWorkspace(@RequestBody Workspace workspace) {
String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
organizationService.checkOrgOwner(currentOrganizationId);
organizationService.checkOrgOwner(workspace.getOrganizationId());
return workspaceService.saveWorkspace(workspace);
}
@ -78,7 +77,6 @@ public class WorkspaceController {
@PostMapping("list/{goPage}/{pageSize}")
public Pager<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) {
request.setOrganizationId(SessionUtils.getCurrentOrganizationId());
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request));
}

View File

@ -25,7 +25,6 @@ public class OperatingLogController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<OperatingLogDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody OperatingLogRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, operatingLogService.list(request));
}

View File

@ -61,8 +61,10 @@ public class WorkspaceService {
MSException.throwException(Translator.get("workspace_name_is_null"));
}
// set organization id
String currentOrgId = SessionUtils.getCurrentOrganizationId();
workspace.setOrganizationId(currentOrgId);
if (StringUtils.isBlank(workspace.getOrganizationId())) {
String currentOrgId = SessionUtils.getCurrentOrganizationId();
workspace.setOrganizationId(currentOrgId);
}
long currentTime = System.currentTimeMillis();

View File

@ -34,7 +34,6 @@ public class TestCaseReviewApiCaseController {
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REVIEW_READ_RELEVANCE_OR_CANCEL)
public Pager<List<ApiTestCaseDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testCaseReviewApiCaseService.relevanceList(request));
}

View File

@ -33,7 +33,6 @@ public class TestCaseReviewScenarioCaseController {
@PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testCaseReviewScenarioCaseService.relevanceList(request));
}

View File

@ -49,8 +49,6 @@ public class TestPlanController {
@PostMapping("/list/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_TRACK_PLAN:READ")
public Pager<List<TestPlanDTOWithMetric>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanService.listTestPlan(request));
}

View File

@ -32,8 +32,6 @@ public class TestPlanReportController {
private TestPlanReportService testPlanReportService;
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<TestPlanReportDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanReportRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanReportService.list(request));
}

View File

@ -41,7 +41,6 @@ public class TestPlanScenarioCaseController {
@PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, testPlanScenarioCaseService.relevanceList(request));
}

View File

@ -114,7 +114,9 @@ public class TestCaseReviewService {
reviewRequest.setUpdateTime(System.currentTimeMillis());
reviewRequest.setCreator(SessionUtils.getUser().getId());//创建人
reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name());
reviewRequest.setProjectId(SessionUtils.getCurrentProjectId());
if (StringUtils.isBlank(reviewRequest.getProjectId())) {
reviewRequest.setProjectId(SessionUtils.getCurrentProjectId());
}
testCaseReviewMapper.insert(reviewRequest);
// 发送通知
String context = getReviewContext(reviewRequest, NoticeConstants.Event.CREATE);
@ -496,7 +498,6 @@ public class TestCaseReviewService {
} else {
request.setReviewerId(user.getId());
}
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(SessionUtils.getCurrentProjectId());
request.setReviewIds(extTestReviewCaseMapper.findRelateTestReviewId(user.getId(), SessionUtils.getCurrentWorkspaceId(), user.getLastProjectId()));

View File

@ -406,9 +406,8 @@ public class TestCaseService {
TestCaseExample testCaseExample = new TestCaseExample();
TestCaseExample.Criteria criteria = testCaseExample.createCriteria();
criteria.andMaintainerEqualTo(request.getUserId());
String projectId = SessionUtils.getCurrentProjectId();
if (StringUtils.isNotBlank(projectId)) {
criteria.andProjectIdEqualTo(projectId);
if (StringUtils.isNotBlank(request.getProjectId())) {
criteria.andProjectIdEqualTo(request.getProjectId());
testCaseExample.setOrderByClause("update_time desc, sort desc");
return testCaseMapper.selectByExample(testCaseExample);
}

View File

@ -149,7 +149,9 @@ public class TestPlanService {
testPlan.setCreateTime(System.currentTimeMillis());
testPlan.setUpdateTime(System.currentTimeMillis());
testPlan.setCreator(SessionUtils.getUser().getId());
testPlan.setProjectId(SessionUtils.getCurrentProjectId());
if (StringUtils.isBlank(testPlan.getProjectId())) {
testPlan.setProjectId(SessionUtils.getCurrentProjectId());
}
testPlanMapper.insert(testPlan);
List<String> userIds = new ArrayList<>();
@ -172,7 +174,7 @@ public class TestPlanService {
public List<TestPlan> getTestPlanByName(String name) {
TestPlanExample example = new TestPlanExample();
example.createCriteria().andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
example.createCriteria()
.andProjectIdEqualTo(SessionUtils.getCurrentProjectId())
.andNameEqualTo(name);
return testPlanMapper.selectByExample(example);
@ -385,9 +387,8 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listTestPlan(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
String projectId = SessionUtils.getCurrentProjectId();
if (StringUtils.isNotBlank(projectId)) {
request.setProjectId(projectId);
if (StringUtils.isNotBlank(request.getProjectId())) {
request.setProjectId(request.getProjectId());
}
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
testPlans.forEach(item -> {
@ -990,7 +991,7 @@ public class TestPlanService {
APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(),
planScenarioID + ":" + request.getTestPlanReportId(),
item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
request.getExecuteType(), item.getProjectId(), request.getReportUserID(),request.getConfig());
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig());
apiScenarioReportMapper.insert(report);
group.setHashTree(scenarios);
testPlan.getHashTree().add(group);

View File

@ -70,6 +70,7 @@ import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem"
import {REPORT_CONFIGS} from "../../common/components/search/search-components";
import ShowMoreBtn from "../../track/case/components/ShowMoreBtn";
import {_filter, _sort} from "@/common/js/tableUtils";
import {getCurrentProjectID} from "@/common/js/utils";
export default {
components: {
@ -121,7 +122,7 @@ export default {
if (this.testId !== 'all') {
this.condition.testId = this.testId;
}
this.condition.projectId = getCurrentProjectID();
let url = "/api/report/list/" + this.currentPage + "/" + this.pageSize;
this.result = this.$post(url, this.condition, response => {
let data = response.data;

View File

@ -28,7 +28,7 @@
{{ item.name }}
</span>
<i class="el-icon-check"
v-if="item.id === currentUserInfo.lastOrganizationId"></i>
v-if="item.id === getCurrentOrganizationId()"></i>
</el-menu-item>
</div>
</el-submenu>
@ -53,7 +53,7 @@
<span class="title">
{{ item.name }}
</span>
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastWorkspaceId"></i>
<i class="el-icon-check" v-if="item.id === getCurrentWorkspaceId()"></i>
</el-menu-item>
</div>
</el-submenu>
@ -61,7 +61,8 @@
</template>
<script>
import {getCurrentUser, saveLocalStorage} from "@/common/js/utils";
import {getCurrentOrganizationId, getCurrentUser, getCurrentWorkspaceId, saveLocalStorage} from "@/common/js/utils";
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
export default {
name: "MsHeaderOrgWs",
@ -108,12 +109,14 @@ export default {
}
},
methods: {
getCurrentOrganizationId,
getCurrentWorkspaceId,
initMenuData() {
this.$get("/organization/list/userorg/" + encodeURIComponent(this.currentUserId), response => {
let data = response.data;
this.organizationList = data;
this.orgListCopy = data;
let org = data.filter(r => r.id === this.currentUser.lastOrganizationId);
let org = data.filter(r => r.id === getCurrentOrganizationId());
if (org.length > 0) {
this.currentOrganizationName = org[0].name;
}
@ -128,7 +131,7 @@ export default {
} else {
this.workspaceList = data;
this.wsListCopy = data;
let workspace = data.filter(r => r.id === this.currentUser.lastWorkspaceId);
let workspace = data.filter(r => r.id === getCurrentWorkspaceId());
if (workspace.length > 0) {
this.currentWorkspaceName = workspace[0].name;
}
@ -147,14 +150,11 @@ export default {
}
this.$post("/user/switch/source/org/" + orgId, {}, response => {
saveLocalStorage(response);
if (response.data.workspaceId) {
localStorage.setItem("workspace_id", response.data.workspaceId);
}
// if (response.data.lastProjectId) {
// localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// } else {
// localStorage.removeItem(PROJECT_ID);
// }
sessionStorage.setItem(ORGANIZATION_ID, orgId);
sessionStorage.setItem(WORKSPACE_ID, response.data.lastWorkspaceId);
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
this.$router.push('/').then(() => {
this.reloadTopMenus();
}).catch(err => err);
@ -167,12 +167,9 @@ export default {
}
this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
saveLocalStorage(response);
localStorage.setItem("workspace_id", workspaceId);
// if (response.data.lastProjectId) {
// localStorage.setItem(PROJECT_ID, response.data.lastProjectId);
// } else {
// localStorage.removeItem(PROJECT_ID);
// }
sessionStorage.setItem(WORKSPACE_ID, workspaceId);
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
this.$router.push('/').then(() => {
this.reloadTopMenus();
}).catch(err => err);

View File

@ -28,6 +28,7 @@ import {getCurrentUser} from "@/common/js/utils";
import AboutUs from "./AboutUs";
import axios from "axios";
import {mapGetters} from "vuex";
import {ORGANIZATION_ID, PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const auth = requireComponent.keys().length > 0 ? requireComponent("./auth/Auth.vue") : {};
@ -53,10 +54,18 @@ export default {
axios.get("/signout").then(response => {
if (response.data.success) {
localStorage.clear();
sessionStorage.removeItem(ORGANIZATION_ID);
sessionStorage.removeItem(WORKSPACE_ID);
sessionStorage.removeItem(PROJECT_ID);
window.location.href = "/login";
}
}).catch(error => {
localStorage.clear();
sessionStorage.removeItem(ORGANIZATION_ID);
sessionStorage.removeItem(WORKSPACE_ID);
sessionStorage.removeItem(PROJECT_ID);
window.location.href = "/login";
});
},

View File

@ -24,7 +24,8 @@
<script>
import SearchList from "@/business/components/common/head/SearchList";
import {PROJECT_NAME} from "../../../../common/js/constants";
import {PROJECT_NAME} from "@/common/js/constants";
import {getCurrentProjectID} from "@/common/js/utils";
export default {
name: "ProjectSwitch",
@ -34,24 +35,27 @@ export default {
components: {SearchList},
watch: {
currentProject() {
localStorage.setItem(PROJECT_NAME, this.currentProject);
sessionStorage.setItem(PROJECT_NAME, this.currentProject);
}
},
methods: {
getCurrentProjectID,
},
data() {
return {
currentProject: this.projectName
}
};
}
}
};
</script>
<style scoped>
.project-name {
display: inline-block;
width: 130px;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.el-divider--horizontal {

View File

@ -17,7 +17,7 @@
<div class="title">
{{ i.name }}
</div>
<i class="el-icon-check" v-if="i.id === currentProjectId"></i>
<i class="el-icon-check" v-if="i.id === getCurrentProjectID()"></i>
</template>
</el-menu-item>
</div>
@ -26,8 +26,15 @@
</template>
<script>
import {getCurrentProjectID, getCurrentUser, getCurrentUserId, saveLocalStorage} from "@/common/js/utils";
import {
getCurrentProjectID,
getCurrentUser,
getCurrentUserId,
getCurrentWorkspaceId,
saveLocalStorage
} from "@/common/js/utils";
import {mapGetters} from "vuex";
import {PROJECT_ID} from "@/common/js/constants";
export default {
name: "SearchList",
@ -54,17 +61,21 @@ export default {
searchArray: [],
searchString: '',
userId: getCurrentUser().id,
currentProjectId: getCurrentProjectID(),
}
};
},
watch: {
searchString(val) {
this.query(val)
this.query(val);
}
},
methods: {
getCurrentProjectID,
init: function () {
this.result = this.$post("/project/list/related", {userId: getCurrentUserId()}, response => {
let data = {
userId: getCurrentUserId(),
workspaceId: getCurrentWorkspaceId()
};
this.result = this.$post("/project/list/related", data, response => {
this.items = response.data;
this.searchArray = response.data;
let projectId = getCurrentProjectID();
@ -79,7 +90,7 @@ export default {
}
}
this.changeProjectName(projectId);
})
});
},
query(queryString) {
this.items = queryString ? this.searchArray.filter(this.createFilter(queryString)) : this.searchArray;
@ -99,6 +110,8 @@ export default {
this.currentProjectId = projectId;
this.$EventBus.$emit('projectChange');
// sessionprojectId
sessionStorage.setItem(PROJECT_ID, projectId);
//
this.reload();
@ -116,7 +129,7 @@ export default {
}
}
}
}
};
</script>
<style scoped>

View File

@ -116,7 +116,7 @@
<script>
import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableOperator from "../../common/components/MsTableOperator";
import {getCurrentProjectID, getCurrentUser, hasRoles} from "@/common/js/utils";
import {getCurrentProjectID, getCurrentUser, getCurrentWorkspaceId, hasRoles} from "@/common/js/utils";
import {PROJECT_ID, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, WORKSPACE_ID} from "@/common/js/constants";
import MsLogDetail from "./LogDetail";
@ -246,11 +246,11 @@
this.getMember();
break;
case "organization":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId);
this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember();
break;
case "workspace":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId);
this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember();
break;
case "project":
@ -267,11 +267,11 @@
this.getMember();
break;
case "organization":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId);
this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember();
break;
case "workspace":
this.initProject("/project/listAll/" + getCurrentUser().lastWorkspaceId);
this.initProject("/project/listAll/" + getCurrentWorkspaceId());
this.getMember();
break;
case "project":

View File

@ -247,6 +247,7 @@ export default {
if (this.form.id) {
saveType = 'update';
}
this.form.organizationId = getCurrentOrganizationId();
this.$post("/workspace/" + saveType, this.form, () => {
this.dialogWsAddVisible = false;
this.dialogWsUpdateVisible = false;
@ -296,7 +297,7 @@ export default {
},
list() {
let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize;
let lastOrganizationId = this.currentUser.lastOrganizationId;
let lastOrganizationId = getCurrentOrganizationId();
// let userRole = this.currentUser.userRoles.filter(r => r.sourceId === lastOrganizationId);
// if (userRole.length > 0) {
// let isOrg_admin = false;
@ -327,6 +328,7 @@ export default {
// this.items = [];
// this.total = 0;
// }
this.condition.organizationId = lastOrganizationId;
this.result = this.$post(url, this.condition, response => {
let data = response.data;
this.items = data.listObject;

View File

@ -245,7 +245,7 @@ export default {
});
},
create() {
let workspaceId = this.currentUser.lastWorkspaceId;
let workspaceId = getCurrentWorkspaceId();
this.getOptions();
if (!workspaceId) {
this.$warning(this.$t('project.please_choose_workspace'));

View File

@ -380,7 +380,7 @@ export default {
});
},
create() {
let workspaceId = this.currentUser.lastWorkspaceId;
let workspaceId = getCurrentWorkspaceId();
this.getOptions();
if (!workspaceId) {
this.$warning(this.$t('project.please_choose_workspace'));

View File

@ -133,7 +133,7 @@
import MsDialogFooter from "../../common/components/MsDialogFooter";
import {
getCurrentOrganizationId, getCurrentProjectID,
getCurrentUser,
getCurrentUser, getCurrentWorkspaceId,
listenGoBack,
removeGoBackListener
} from "../../../../common/js/utils";
@ -197,19 +197,19 @@
return getCurrentUser();
},
initTableData() {
if (this.currentUser().lastWorkspaceId === null) {
if (getCurrentWorkspaceId() === null) {
return false;
}
this.loading = true;
let param = {
name: this.condition.name,
workspaceId: this.currentUser().lastWorkspaceId
workspaceId: getCurrentWorkspaceId()
};
this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
let data = response.data;
this.tableData = data.listObject;
let url = "/user/group/list/ws/" + this.currentUser().lastWorkspaceId;
let url = "/user/group/list/ws/" + getCurrentWorkspaceId();
for (let i = 0; i < this.tableData.length; i++) {
this.$get(url + "/" + encodeURIComponent(this.tableData[i].id), response => {
let groups = response.data;
@ -260,7 +260,7 @@
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get('/user/ws/member/delete/' + this.currentUser().lastWorkspaceId + '/' + encodeURIComponent(row.id),() => {
this.result = this.$get('/user/ws/member/delete/' + getCurrentWorkspaceId() + '/' + encodeURIComponent(row.id), () => {
this.$success(this.$t('commons.remove_success'));
this.initTableData();
});
@ -286,7 +286,7 @@
email: this.form.email,
phone: this.form.phone,
groupIds: this.form.groupIds,
workspaceId: this.currentUser().lastWorkspaceId
workspaceId: getCurrentWorkspaceId()
}
this.$refs[formName].validate((valid) => {
if (valid) {
@ -304,7 +304,7 @@
// name: this.condition.name,
// organizationId: this.currentUser().lastOrganizationId
// };
let wsId = this.currentUser().lastWorkspaceId;
let wsId = getCurrentWorkspaceId();
if (typeof wsId == "undefined" || wsId == null || wsId == "") {
this.$warning(this.$t('workspace.please_select_a_workspace_first'));
return false;
@ -339,7 +339,7 @@
let param = {
userIds: userIds,
groupIds: this.form.groupIds,
workspaceId: this.currentUser().lastWorkspaceId
workspaceId: getCurrentWorkspaceId()
};
this.result = this.$post("user/ws/member/add", param, () => {
this.$success(this.$t('commons.save_success'));

View File

@ -20,6 +20,7 @@ export const ROLE_TEST_MANAGER = 'test_manager';
export const ROLE_TEST_USER = 'test_user';
export const ROLE_TEST_VIEWER = 'test_viewer';
export const ORGANIZATION_ID = 'organization_id';
export const WORKSPACE_ID = 'workspace_id';
export const CURRENT_PROJECT = 'current_project';
export const PROJECT_ID = 'project_id';

View File

@ -2,6 +2,7 @@ import {
COUNT_NUMBER,
COUNT_NUMBER_SHALLOW,
LicenseKey,
ORGANIZATION_ID,
ORIGIN_COLOR,
ORIGIN_COLOR_SHALLOW,
PRIMARY_COLOR,
@ -12,7 +13,8 @@ import {
ROLE_TEST_MANAGER,
ROLE_TEST_USER,
ROLE_TEST_VIEWER,
TokenKey
TokenKey,
WORKSPACE_ID
} from "./constants";
import axios from "axios";
import {jsPDF} from "jspdf";
@ -178,13 +180,15 @@ export function checkoutTestManagerOrTestUser() {
}
export function getCurrentOrganizationId() {
let user = getCurrentUser();
return user.lastOrganizationId;
return sessionStorage.getItem(ORGANIZATION_ID);
}
export function getCurrentWorkspaceId() {
let user = getCurrentUser();
return user.lastWorkspaceId;
return sessionStorage.getItem(WORKSPACE_ID);
}
export function getCurrentProjectID() {
return sessionStorage.getItem(PROJECT_ID);
}
export function getCurrentUser() {
@ -196,11 +200,6 @@ export function getCurrentUserId() {
return user.id;
}
export function getCurrentProjectID() {
let user = getCurrentUser();
return user.lastProjectId;
}
export function enableModules(...modules) {
for (let module of modules) {
let moduleStatus = localStorage.getItem('module_' + module);
@ -214,6 +213,15 @@ export function enableModules(...modules) {
export function saveLocalStorage(response) {
// 登录信息保存 cookie
localStorage.setItem(TokenKey, JSON.stringify(response.data));
if (!sessionStorage.getItem(PROJECT_ID)) {
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
}
if (!sessionStorage.getItem(ORGANIZATION_ID)) {
sessionStorage.setItem(ORGANIZATION_ID, response.data.lastOrganizationId);
}
if (!sessionStorage.getItem(WORKSPACE_ID)) {
sessionStorage.setItem(WORKSPACE_ID, response.data.lastWorkspaceId);
}
let rolesArray = response.data.roles;
let roles = rolesArray.map(r => r.id);
// 保存角色