Merge remote-tracking branch 'origin/master'

This commit is contained in:
song.tianyang 2021-02-22 11:41:40 +08:00
commit cb1b9b1d67
13 changed files with 311 additions and 212 deletions

View File

@ -10,16 +10,11 @@ import io.metersphere.api.dto.datacount.response.ApiDataCountDTO;
import io.metersphere.api.dto.datacount.response.ExecutedCaseInfoDTO;
import io.metersphere.api.dto.datacount.response.TaskInfoResult;
import io.metersphere.api.dto.definition.RunDefinitionRequest;
import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter;
import io.metersphere.api.service.*;
import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.ApiTest;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.constants.ScheduleGroup;
import io.metersphere.commons.utils.CronUtils;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
@ -28,24 +23,14 @@ import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.performance.service.PerformanceTestService;
import io.metersphere.service.CheckPermissionService;
import io.metersphere.service.FileService;
import io.metersphere.service.ScheduleService;
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.jorphan.collections.HashTree;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;

View File

@ -160,5 +160,11 @@ public class ApiAutomationController {
return apiAutomationService.export(request);
}
@PostMapping(value = "/export/jmx")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public List<ApiScenrioExportJmx> exportJmx(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.exportJmx(request);
}
}

View File

@ -0,0 +1,16 @@
package io.metersphere.api.dto.automation;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ApiScenrioExportJmx {
private String name;
private String jmx;
public ApiScenrioExportJmx(String name, String jmx) {
this.name = name;
this.jmx = jmx;
}
}

View File

@ -88,7 +88,7 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
preInitPool(request.getProjectId(), testPlan);
MsScenario scenario = new MsScenario();
scenario.setReferenced("REF");
scenario.setReferenced("IMPORT");
jmterHashTree(testPlan, scenario);
this.projectId = request.getProjectId();
ScenarioImport scenarioImport = new ScenarioImport();
@ -233,24 +233,24 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
elementNode.setConsumerAndService(consumerAndService);
List<MethodArgument> methodArguments = Constants.getMethodArgs(sampler);
List<KeyValue> methodArgs = new LinkedList<>();
if (CollectionUtils.isNotEmpty(methodArguments)) {
List<KeyValue> methodArgs = new LinkedList<>();
methodArguments.forEach(item -> {
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
methodArgs.add(keyValue);
});
elementNode.setArgs(methodArgs);
}
elementNode.setArgs(methodArgs);
List<MethodArgument> arguments = Constants.getAttachmentArgs(sampler);
List<KeyValue> attachmentArgs = new LinkedList<>();
if (CollectionUtils.isNotEmpty(arguments)) {
List<KeyValue> methodArgs = new LinkedList<>();
arguments.forEach(item -> {
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
methodArgs.add(keyValue);
attachmentArgs.add(keyValue);
});
elementNode.setAttachmentArgs(methodArgs);
}
elementNode.setAttachmentArgs(attachmentArgs);
}
/**

View File

@ -164,9 +164,9 @@ public abstract class MsTestElement {
}
public Arguments addArguments(ParameterConfig config) {
Arguments arguments = new Arguments();
if (config != null && config.getConfig() != null && config.getConfig().getCommonConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().getCommonConfig().getVariables())) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
arguments.setName(name + "Variables");
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
@ -174,8 +174,9 @@ public abstract class MsTestElement {
config.getConfig().getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
return arguments;
}
return arguments;
return null;
}
protected EnvironmentConfig getEnvironmentConfig(String environmentId) {

View File

@ -95,17 +95,18 @@ public class MsJDBCSampler extends MsTestElement {
}
private Arguments arguments(String name, List<KeyValue> variables) {
Arguments arguments = new Arguments();
if (CollectionUtils.isNotEmpty(variables)) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
arguments.setName(name);
arguments.setName(name + "JDBC_Argument");
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
);
return arguments;
}
return arguments;
return null;
}
private JDBCSampler jdbcSampler(ParameterConfig config) {

View File

@ -435,6 +435,47 @@ public class ApiAutomationService {
return jmeterHashTree;
}
private String generateJmx(ApiScenarioWithBLOBs apiScenario) {
HashTree jmeterHashTree = new ListedHashTree();
MsTestPlan testPlan = new MsTestPlan();
testPlan.setHashTree(new LinkedList<>());
try {
MsThreadGroup group = new MsThreadGroup();
group.setLabel(apiScenario.getName());
group.setName(apiScenario.getName());
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JSONObject element = JSON.parseObject(apiScenario.getScenarioDefinition());
MsScenario scenario = JSONObject.parseObject(apiScenario.getScenarioDefinition(), MsScenario.class);
// 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
new TypeReference<LinkedList<MsTestElement>>() {
});
scenario.setHashTree(elements);
}
if (StringUtils.isNotEmpty(element.getString("variables"))) {
LinkedList<ScenarioVariable> variables = mapper.readValue(element.getString("variables"),
new TypeReference<LinkedList<ScenarioVariable>>() {
});
scenario.setVariables(variables);
}
group.setEnableCookieShare(scenario.isEnableCookieShare());
group.setHashTree(new LinkedList<MsTestElement>() {{
this.add(scenario);
}});
testPlan.getHashTree().add(group);
} catch (Exception ex) {
MSException.throwException(ex.getMessage());
}
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
return testPlan.getJmx(jmeterHashTree);
}
/**
* 场景测试执行
*
@ -515,7 +556,6 @@ public class ApiAutomationService {
ParameterConfig config = new ParameterConfig();
config.setConfig(envConfig);
HashTree hashTree = request.getTestElement().generateHashTree(config);
System.out.println(request.getTestElement().getJmx(hashTree));
// 调用执行方法
createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
SessionUtils.getUserId());
@ -668,7 +708,7 @@ public class ApiAutomationService {
HashTree jmeterHashTree = generateHashTree(apiScenarios, request, null);
String jmx = testPlan.getJmx(jmeterHashTree);
jmx = apiTestService.updateJmxString(jmx,testName,true);
jmx = apiTestService.updateJmxString(jmx, testName, true);
//将ThreadGroup的testname改为接口名称
// Document doc = DocumentHelper.parseText(jmx);// 获取可续保保单列表报文模板
@ -805,16 +845,32 @@ public class ApiAutomationService {
return apiImport;
}
public ApiScenrioExportResult export(ApiScenarioBatchRequest request) {
private List<ApiScenarioWithBLOBs> getExportResult(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andIdIn(request.getIds());
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = apiScenarioMapper.selectByExampleWithBLOBs(example);
ApiScenrioExportResult result = new ApiScenrioExportResult();
result.setData(apiScenarioWithBLOBs);
return apiScenarioWithBLOBs;
}
public ApiScenrioExportResult export(ApiScenarioBatchRequest request) {
ApiScenrioExportResult result = new ApiScenrioExportResult();
result.setData(getExportResult(request));
result.setProjectId(request.getProjectId());
result.setVersion(System.getenv("MS_VERSION"));
return result;
}
public List<ApiScenrioExportJmx> exportJmx(ApiScenarioBatchRequest request) {
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = getExportResult(request);
// 生成jmx
List<ApiScenrioExportJmx> resList = new ArrayList<>();
apiScenarioWithBLOBs.forEach(item -> {
ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(generateJmx(item), item.getName(), true));
resList.add(scenrioExportJmx);
});
return resList;
}
}

@ -1 +1 @@
Subproject commit 44bcc9893033900f95c99068cd4edec740465dfe
Subproject commit b9042074b780205e275c674f64417799110519fd

View File

@ -9,6 +9,7 @@
@setNodeTree="setNodeTree"
@enableTrash="enableTrash"
@exportAPI="exportAPI"
@exportJmx="exportJmx"
@refreshAll="refreshAll"
:type="'edit'"
ref="nodeTree"/>
@ -69,7 +70,6 @@
import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
import MsEditApiScenario from "./scenario/EditApiScenario";
import {getCurrentProjectID} from "../../../../common/js/utils";
import {PROJECT_NAME} from "../../../../common/js/constants";
export default {
name: "ApiAutomation",
@ -133,6 +133,9 @@
exportAPI() {
this.$refs.apiScenarioList.exportApi();
},
exportJmx(){
this.$refs.apiScenarioList.exportJmx();
},
checkRedirectEditPage(redirectParam) {
if (redirectParam != null) {
let selectParamArr = redirectParam.split("edit:");

View File

@ -167,50 +167,50 @@
</template>
<script>
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTag from "../../../common/components/MsTag";
import {downloadFile, getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsTableMoreBtn from "./TableMoreBtn";
import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns";
import MsTestPlanList from "./testplan/TestPlanList";
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
import {API_SCENARIO_CONFIGS} from "@/business/components/common/components/search/search-components";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import PriorityTableItem from "../../../track/common/tableItems/planview/PriorityTableItem";
import PlanStatusTableItem from "../../../track/common/tableItems/plan/PlanStatusTableItem";
import BatchEdit from "../../../track/case/components/BatchEdit";
import {API_SCENARIO_LIST, TEST_CASE_LIST, TEST_PLAN_LIST, WORKSPACE_ID} from "../../../../../common/js/constants";
import {PROJECT_NAME} from "../../../../../common/js/constants";
import EnvironmentSelect from "../../definition/components/environment/EnvironmentSelect";
import BatchMove from "../../../track/case/components/BatchMove";
import {_sort} from "@/common/js/tableUtils";
import {Api_Scenario_List} from "@/business/components/common/model/JsonData";
import HeaderCustom from "@/business/components/common/head/HeaderCustom";
import {
_filter,
_handleSelect,
_handleSelectAll,
getSelectDataCounts,
setUnSelectIds, toggleAllSelection
} from "@/common/js/tableUtils";
import MsTableHeader from "@/business/components/common/components/MsTableHeader";
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTag from "../../../common/components/MsTag";
import {downloadFile, getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsTableMoreBtn from "./TableMoreBtn";
import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns";
import MsTestPlanList from "./testplan/TestPlanList";
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
import {API_SCENARIO_CONFIGS} from "@/business/components/common/components/search/search-components";
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import PriorityTableItem from "../../../track/common/tableItems/planview/PriorityTableItem";
import PlanStatusTableItem from "../../../track/common/tableItems/plan/PlanStatusTableItem";
import BatchEdit from "../../../track/case/components/BatchEdit";
import {API_SCENARIO_LIST, TEST_CASE_LIST, TEST_PLAN_LIST, WORKSPACE_ID} from "../../../../../common/js/constants";
import {PROJECT_NAME} from "../../../../../common/js/constants";
import EnvironmentSelect from "../../definition/components/environment/EnvironmentSelect";
import BatchMove from "../../../track/case/components/BatchMove";
import {_sort} from "@/common/js/tableUtils";
import {Api_Scenario_List} from "@/business/components/common/model/JsonData";
import HeaderCustom from "@/business/components/common/head/HeaderCustom";
import {
_filter,
_handleSelect,
_handleSelectAll,
getSelectDataCounts,
setUnSelectIds, toggleAllSelection
} from "@/common/js/tableUtils";
export default {
name: "MsApiScenarioList",
components: {
HeaderCustom,
BatchMove,
EnvironmentSelect,
BatchEdit,
PlanStatusTableItem,
PriorityTableItem,
MsTableHeaderSelectPopover,
MsTablePagination,
MsTableMoreBtn,
ShowMoreBtn,
MsTableHeader,
export default {
name: "MsApiScenarioList",
components: {
HeaderCustom,
BatchMove,
EnvironmentSelect,
BatchEdit,
PlanStatusTableItem,
PriorityTableItem,
MsTableHeaderSelectPopover,
MsTablePagination,
MsTableMoreBtn,
ShowMoreBtn,
MsTableHeader,
MsTag,
MsApiReportDetail,
MsScenarioExtendButtons,
@ -554,12 +554,15 @@ export default {
_handleSelectAll(this, selection, this.tableData, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
this.$emit('selection', selection);
},
handleSelect(selection, row) {
_handleSelect(this, selection, row, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
this.$emit('selection', selection);
},
isSelectDataAll(data) {
this.condition.selectAll = data;
setUnSelectIds(this.tableData, this.condition, this.selectRows);
@ -672,6 +675,25 @@ export default {
downloadFile("Metersphere_Scenario_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
});
},
exportJmx() {
let param = {};
this.buildBatchParam(param);
if (param.ids === undefined || param.ids.length < 1) {
this.$warning(this.$t("api_test.automation.scenario.check_case"));
return;
}
this.loading = true;
this.result = this.$post("/api/automation/export/jmx", param, response => {
this.loading = false;
let obj = response.data;
console.log(obj)
if (obj && obj.length > 0) {
obj.forEach(item => {
downloadFile(item.name + ".jmx", item.jmx);
})
}
});
},
buildApiPath(scenarios) {
scenarios.forEach((scenario) => {
this.moduleOptions.forEach(item => {

View File

@ -25,7 +25,8 @@
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="add-scenario">{{ $t('api_test.automation.add_scenario') }}</el-dropdown-item>
<el-dropdown-item command="import">{{ $t('api_test.api_import.label') }}</el-dropdown-item>
<el-dropdown-item command="export">{{ $t('report.export') }}</el-dropdown-item>
<el-dropdown-item command="export">{{ $t('report.export') }}MS</el-dropdown-item>
<el-dropdown-item command="exportJmx">{{ $t('report.export') }}JMX</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
@ -33,14 +34,14 @@
<module-trash-button v-if="!isReadOnly" :condition="condition" :exe="enableTrash"/>
<!-- 是否保留这个 -->
<!--<api-scenario-module-header-->
<!--:condition="condition"-->
<!--:current-module="currentModule"-->
<!--:is-read-only="isReadOnly"-->
<!--:project-id="projectId"-->
<!--@exportAPI="exportAPI"-->
<!--@addScenario="addScenario"-->
<!--@refreshTable="$emit('refreshTable')"-->
<!--@refresh="refresh"/>-->
<!--:condition="condition"-->
<!--:current-module="currentModule"-->
<!--:is-read-only="isReadOnly"-->
<!--:project-id="projectId"-->
<!--@exportAPI="exportAPI"-->
<!--@addScenario="addScenario"-->
<!--@refreshTable="$emit('refreshTable')"-->
<!--@refresh="refresh"/>-->
</template>
</ms-node-tree>
@ -56,27 +57,26 @@
</template>
<script>
import SelectMenu from "../../../track/common/SelectMenu";
import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario";
import {getCurrentProjectID} from "@/common/js/utils";
import MsNodeTree from "../../../track/common/NodeTree";
import {buildNodePath} from "../../definition/model/NodeTree";
import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton";
import ApiScenarioModuleHeader from "@/business/components/api/automation/scenario/module/ApiScenarioModuleHeader";
import ApiImport from "./common/ScenarioImport";
import SelectMenu from "../../../track/common/SelectMenu";
import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario";
import {getCurrentProjectID} from "@/common/js/utils";
import MsNodeTree from "../../../track/common/NodeTree";
import {buildNodePath} from "../../definition/model/NodeTree";
import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton";
import ApiImport from "./common/ScenarioImport";
export default {
name: 'MsApiScenarioModule',
components: {
ApiImport,
ModuleTrashButton,
MsNodeTree,
MsAddBasisScenario,
SelectMenu,
},
props: {
isReadOnly: {
type: Boolean,
export default {
name: 'MsApiScenarioModule',
components: {
ApiImport,
ModuleTrashButton,
MsNodeTree,
MsAddBasisScenario,
SelectMenu,
},
props: {
isReadOnly: {
type: Boolean,
default() {
return false
}
@ -145,6 +145,9 @@ export default {
case "export":
this.$emit('exportAPI');
break;
case "exportJmx":
this.$emit('exportJmx');
break;
}
},
list() {

View File

@ -2,13 +2,13 @@
<relevance-dialog :title="$t('api_test.automation.scenario_import')" ref="relevanceDialog">
<template v-slot:aside>
<ms-api-scenario-module
@nodeSelectEvent="nodeChange"
@refreshTable="refresh"
@setModuleOptions="setModuleOptions"
@enableTrash="false"
:is-read-only="true"
ref="nodeTree"/>
<ms-api-scenario-module
@nodeSelectEvent="nodeChange"
@refreshTable="refresh"
@setModuleOptions="setModuleOptions"
@enableTrash="false"
:is-read-only="true"
ref="nodeTree"/>
</template>
<ms-api-scenario-list
@ -27,94 +27,98 @@
</template>
<script>
import ScenarioRelevanceCaseList from "./RelevanceCaseList";
import MsApiModule from "../../../definition/components/module/ApiModule";
import MsContainer from "../../../../common/components/MsContainer";
import MsAsideContainer from "../../../../common/components/MsAsideContainer";
import MsMainContainer from "../../../../common/components/MsMainContainer";
import ScenarioRelevanceApiList from "./RelevanceApiList";
import MsApiScenarioModule from "../ApiScenarioModule";
import MsApiScenarioList from "../ApiScenarioList";
import {getUUID} from "../../../../../../common/js/utils";
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
export default {
name: "ScenarioRelevance",
components: {
RelevanceDialog,
MsApiScenarioList,
MsApiScenarioModule,
MsMainContainer, MsAsideContainer, MsContainer},
data() {
return {
result: {},
currentProtocol: null,
selectNodeIds: [],
moduleOptions: {},
isApiListEnable: true,
currentScenario: [],
currentScenarioIds: [],
}
import ScenarioRelevanceCaseList from "./RelevanceCaseList";
import MsApiModule from "../../../definition/components/module/ApiModule";
import MsContainer from "../../../../common/components/MsContainer";
import MsAsideContainer from "../../../../common/components/MsAsideContainer";
import MsMainContainer from "../../../../common/components/MsMainContainer";
import ScenarioRelevanceApiList from "./RelevanceApiList";
import MsApiScenarioModule from "../ApiScenarioModule";
import MsApiScenarioList from "../ApiScenarioList";
import {getUUID} from "../../../../../../common/js/utils";
import RelevanceDialog from "../../../../track/plan/view/comonents/base/RelevanceDialog";
export default {
name: "ScenarioRelevance",
components: {
RelevanceDialog,
MsApiScenarioList,
MsApiScenarioModule,
MsMainContainer, MsAsideContainer, MsContainer
},
data() {
return {
result: {},
currentProtocol: null,
selectNodeIds: [],
moduleOptions: {},
isApiListEnable: true,
currentScenario: [],
currentScenarioIds: [],
}
},
methods: {
reference() {
let scenarios = [];
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
return;
}
this.currentScenario.forEach(item => {
let obj = {id: item.id, name: item.name, type: "scenario", referenced: 'REF', resourceId: getUUID()};
scenarios.push(obj);
});
this.$emit('save', scenarios);
this.close();
},
methods: {
reference() {
let scenarios = [];
if (!this.currentScenario || this.currentScenario.length < 1) {
this.$emit('请选择场景');
return;
}
this.currentScenario.forEach(item => {
let obj = {id: item.id, name: item.name, type: "scenario", referenced: 'REF', resourceId: getUUID()};
scenarios.push(obj);
});
this.$emit('save', scenarios);
this.close();
},
copy() {
let scenarios = [];
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$emit('请选择场景');
return;
}
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
if (response.data) {
response.data.forEach(item => {
let scenarioDefinition = JSON.parse(item.scenarioDefinition);
copy() {
let scenarios = [];
if (!this.currentScenarioIds || this.currentScenarioIds.length < 1) {
this.$warning('请选择场景');
return;
}
this.result = this.$post("/api/automation/getApiScenarios/", this.currentScenarioIds, response => {
if (response.data) {
response.data.forEach(item => {
let scenarioDefinition = JSON.parse(item.scenarioDefinition);
if (scenarioDefinition && scenarioDefinition.hashTree) {
let obj = {id: item.id, name: item.name, type: "scenario", referenced: 'Copy', resourceId: getUUID(), hashTree: scenarioDefinition.hashTree};
scenarios.push(obj);
});
this.$emit('save', scenarios);
this.close();
}
})
},
close() {
this.refresh();
this.$refs.relevanceDialog.close();
},
open() {
this.$refs.relevanceDialog.open();
if (this.$refs.apiScenarioList) {
this.$refs.apiScenarioList.search();
}
});
this.$emit('save', scenarios);
this.close();
}
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
refresh() {
this.$refs.apiScenarioList.search();
},
setData(data) {
this.currentScenario = Array.from(data).map(row => row);
this.currentScenarioIds = Array.from(data).map(row => row.id);
},
}
})
},
close() {
this.refresh();
this.$refs.relevanceDialog.close();
},
open() {
this.$refs.relevanceDialog.open();
if (this.$refs.apiScenarioList) {
this.$refs.apiScenarioList.search();
}
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
refresh() {
this.$refs.apiScenarioList.search();
},
setData(data) {
this.currentScenario = Array.from(data).map(row => row);
this.currentScenarioIds = Array.from(data).map(row => row.id);
},
}
}
</script>
<style scoped>

View File

@ -22,23 +22,23 @@
</template>
<script>
import MsSqlBasisParameters from "../../../definition/components/request/database/BasisParameters";
import MsTcpBasisParameters from "../../../definition/components/request/tcp/TcpBasisParameters";
import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm";
import ApiBaseComponent from "../common/ApiBaseComponent";
import MsSqlBasisParameters from "../../../definition/components/request/database/BasisParameters";
import MsTcpBasisParameters from "../../../definition/components/request/tcp/TcpBasisParameters";
import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm";
import ApiBaseComponent from "../common/ApiBaseComponent";
export default {
name: "ApiScenarioComponent",
props: {
scenario: {},
node: {},
draggable: {
type: Boolean,
default: false,
export default {
name: "ApiScenarioComponent",
props: {
scenario: {},
node: {},
draggable: {
type: Boolean,
default: false,
},
},
},
watch: {},
watch: {},
created() {
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) {
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
@ -79,8 +79,10 @@ export default {
this.$emit('remove', this.scenario, this.node);
},
active(item) {
item.active = !item.active;
this.reload();
if (item && item.active) {
item.active = !item.active;
this.reload();
}
},
copyRow() {
this.$emit('copyRow', this.scenario, this.node);