diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java index c1f3d090fd..52ab78a23b 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java @@ -9,4 +9,5 @@ import java.util.List; public interface ExtApiProjectMapper { List getUserProject(@Param("proRequest") ApiProjectRequest request); + ProjectDTO getProject(String scenarioId); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml index 5a822b60ac..78f7761f2d 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml @@ -23,4 +23,12 @@ + + diff --git a/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java b/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java index f7afeff486..684b191639 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java @@ -59,4 +59,9 @@ public class ExtProjectController { public List getUserProject(@RequestBody ApiProjectRequest request) { return extProjectApplicationService.getUserProject(request); } + + @GetMapping("/api/project/get/{id}") + public ProjectDTO getProject(@PathVariable String id) { + return extProjectApplicationService.getProject(id); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java index 694fb09889..c28ee2d1d7 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java @@ -179,4 +179,8 @@ public class ExtProjectApplicationService { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); return extApiProjectMapper.getUserProject(request); } + + public ProjectDTO getProject(String id) { + return extApiProjectMapper.getProject(id); + } } diff --git a/api-test/frontend/src/api/project.js b/api-test/frontend/src/api/project.js index 6427a7fea5..58526dc0d7 100644 --- a/api-test/frontend/src/api/project.js +++ b/api-test/frontend/src/api/project.js @@ -54,3 +54,9 @@ export function projectRelated(params) { export function apiProjectRelated(params) { return post('/api/project/list/related', params); } + +export function apiProjectByScenarioId(scenarioId) { + return get('/api/project/get/' + scenarioId); +} + + diff --git a/api-test/frontend/src/business/automation/report/ApiReportViewHeader.vue b/api-test/frontend/src/business/automation/report/ApiReportViewHeader.vue index fa568c15a5..4ab15528ee 100644 --- a/api-test/frontend/src/business/automation/report/ApiReportViewHeader.vue +++ b/api-test/frontend/src/business/automation/report/ApiReportViewHeader.vue @@ -114,10 +114,11 @@ import { generateShareInfoWithExpired, getShareRedirectUrl } from '../../../api/share'; import { getCurrentProjectID, getCurrentWorkspaceId } from 'metersphere-frontend/src/utils/token'; import MsTag from 'metersphere-frontend/src/components/MsTag'; -import { getProjectApplicationConfig } from '../../../api/project'; +import {apiProjectByScenarioId, getProjectApplicationConfig} from '../../../api/project'; import { apiTestReRun } from '../../../api/xpack'; import { getUUID } from 'metersphere-frontend/src/utils'; import { getApiScenarioIdByPlanScenarioId } from '@/api/test-plan'; +import {getScenarioReport} from '../../../api/scenario-report'; export default { name: 'MsApiReportViewHeader', @@ -189,13 +190,19 @@ export default { let resourceId = this.scenarioId; getApiScenarioIdByPlanScenarioId(this.scenarioId).then((res) => { resourceId = res.data; - this.showDetails(resourceId); + apiProjectByScenarioId(resourceId).then((response) =>{ + if (response.data) { + let projectId = response.data.id; + let workspaceId = response.data.workspaceId; + let projectName = response.data.name; + let workspaceName = response.data.workspaceName; + this.showDetails(resourceId, projectId, projectName, workspaceId, workspaceName); + } + }) }); }, - showDetails(resourceId) { + showDetails(resourceId, projectId, projectName, workspaceId, workspaceName) { let uuid = getUUID().substring(1, 5); - let projectId = getCurrentProjectID(); - let workspaceId = getCurrentWorkspaceId(); let prefix = '/#'; if ( this.$route && @@ -205,7 +212,7 @@ export default { ) { prefix = ''; } - let path = `${prefix}/api/automation/?redirectID=${uuid}&dataType=scenario&projectId=${projectId}&workspaceId=${workspaceId}&resourceId=${resourceId}`; + let path = `${prefix}/api/automation/?redirectID=${uuid}&dataType=scenario&projectId=${projectId}&workspaceId=${workspaceId}&resourceId=${resourceId}&projectName=${projectName}&workspaceName=${workspaceName}`; let data = this.$router.resolve({ path: path, }); diff --git a/api-test/frontend/src/business/head/ApiHeaderMenus.vue b/api-test/frontend/src/business/head/ApiHeaderMenus.vue index 3c48d062eb..91a80cd36a 100644 --- a/api-test/frontend/src/business/head/ApiHeaderMenus.vue +++ b/api-test/frontend/src/business/head/ApiHeaderMenus.vue @@ -34,6 +34,7 @@ import MsShowAll from 'metersphere-frontend/src/components/head/ShowAll'; import MsCreateButton from 'metersphere-frontend/src/components/head/CreateButton'; import ProjectChange from 'metersphere-frontend/src/components/head/ProjectSwitch'; import MsHeaderRightMenus from 'metersphere-frontend/src/components/layout/HeaderRightMenus'; +import { PROJECT_ID, PROJECT_NAME, WORKSPACE, WORKSPACE_ID } from 'metersphere-frontend/src/utils/constants'; export default { name: 'MsApiHeaderMenus', @@ -56,6 +57,16 @@ export default { $route: { immediate: true, handler(to) { + if (to.path === "/api/automation/") { + if (to.query.projectName && to.query.projectId) { + sessionStorage.setItem(PROJECT_NAME, to.query.projectName); + sessionStorage.setItem(PROJECT_ID, to.query.projectId); + } + if (to.query.workspaceName && to.query.workspaceId) { + sessionStorage.setItem(WORKSPACE, to.query.workspaceName); + sessionStorage.setItem(WORKSPACE_ID, to.query.workspaceId); + } + } let path = to.path.split('/', 4); this.currentPath = '/' + path[1] + '/' + path[2]; if (path[3] === 'report') {