fix(接口自动化): 域名根据环境切换问题

This commit is contained in:
shiziyuan9527 2021-11-26 12:33:12 +08:00 committed by 刘瑞斌
parent 10b3c79125
commit 681a02b952
5 changed files with 38 additions and 24 deletions

View File

@ -205,12 +205,14 @@
:project-list="projectList" :project-list="projectList"
:env-map="projectEnvMap" :env-map="projectEnvMap"
:env-group-id="envGroupId" :env-group-id="envGroupId"
:environment-type="environmentType"
@remove="remove" @remove="remove"
@copyRow="copyRow" @copyRow="copyRow"
@suggestClick="suggestClick" @suggestClick="suggestClick"
@refReload="refReload" @refReload="refReload"
@runScenario="runDebug" @runScenario="runDebug"
@stopScenario="stop" @stopScenario="stop"
@setDomain="setDomain"
@openScenario="openScenario"/> @openScenario="openScenario"/>
</span> </span>
</el-tree> </el-tree>
@ -528,7 +530,7 @@ export default {
currentUser: () => { currentUser: () => {
return getCurrentUser(); return getCurrentUser();
}, },
setDomain(flag) { setDomain() {
if (this.projectEnvMap && this.projectEnvMap.size > 0) { if (this.projectEnvMap && this.projectEnvMap.size > 0) {
let scenario = { let scenario = {
id: this.currentScenario.id, id: this.currentScenario.id,

View File

@ -9,7 +9,7 @@
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="request.url" <el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="request.url"
style="width: 50%" size="small" @blur="urlChange" :disabled="request.disabled"> style="width: 50%" size="small" @blur="urlChange" :disabled="request.disabled">
</el-input> </el-input>
<el-checkbox v-if="isCustomizeReq" class="is-ref-environment" v-model="request.isRefEnvironment"> <el-checkbox v-if="isCustomizeReq" class="is-ref-environment" v-model="request.isRefEnvironment" @change="setDomain" :disabled="request.disabled">
{{ $t('api_test.request.refer_to_environment') }} {{ $t('api_test.request.refer_to_environment') }}
</el-checkbox> </el-checkbox>
</div> </div>
@ -123,6 +123,9 @@ export default {
this.$error(this.$t('api_test.request.url_invalid'), 2000); this.$error(this.$t('api_test.request.url_invalid'), 2000);
} }
}, },
setDomain() {
this.$emit("setDomain");
}
} }
} }
</script> </script>

View File

@ -52,7 +52,7 @@
<!--请求内容--> <!--请求内容-->
<template v-slot:request> <template v-slot:request>
<legend style="width: 100%"> <legend style="width: 100%">
<customize-req-info :is-customize-req="isCustomizeReq" :request="request"/> <customize-req-info :is-customize-req="isCustomizeReq" :request="request" @setDomain="setDomain"/>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p> <p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<ms-api-request-form <ms-api-request-form
v-if="request.protocol==='HTTP' || request.type==='HTTPSamplerProxy'" v-if="request.protocol==='HTTP' || request.type==='HTTPSamplerProxy'"
@ -617,6 +617,9 @@ export default {
this.loading = false; this.loading = false;
this.$emit('refReload', this.request, this.node); this.$emit('refReload', this.request, this.node);
}, },
setDomain() {
this.$emit("setDomain");
},
reload() { reload() {
this.loading = true this.loading = true
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -41,7 +41,7 @@
</template> </template>
<template v-slot:scenarioEnable> <template v-slot:scenarioEnable>
<el-tooltip content="启用场景环境:当前步骤使用场景原始环境配置运行" placement="top"> <el-tooltip content="启用场景环境:当前步骤使用场景原始环境配置运行" placement="top">
<el-checkbox v-model="scenario.environmentEnable" @change="checkEnv">启用场景环境</el-checkbox> <el-checkbox v-model="scenario.environmentEnable" @change="checkEnv" :disabled="scenario.disabled">启用场景环境</el-checkbox>
</el-tooltip> </el-tooltip>
</template> </template>
<template v-slot:button> <template v-slot:button>
@ -66,8 +66,7 @@ import MsTcpBasisParameters from "../../../definition/components/request/tcp/Tcp
import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters"; import MsDubboBasisParameters from "../../../definition/components/request/dubbo/BasisParameters";
import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm"; import MsApiRequestForm from "../../../definition/components/request/http/ApiHttpRequestForm";
import ApiBaseComponent from "../common/ApiBaseComponent"; import ApiBaseComponent from "../common/ApiBaseComponent";
import {getCurrentProjectID, getUUID} from "@/common/js/utils"; import {getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils";
import {getUrl} from "@/business/components/api/automation/scenario/component/urlhelper";
export default { export default {
name: "ApiScenarioComponent", name: "ApiScenarioComponent",
@ -88,7 +87,10 @@ export default {
default: false, default: false,
}, },
currentEnvironmentId: String, currentEnvironmentId: String,
projectList: Array projectList: Array,
environmentType: String,
environmentGroupId: String,
envMap: Map
}, },
watch: { watch: {
message() { message() {
@ -174,30 +176,31 @@ export default {
this.$emit('stopScenario'); this.$emit('stopScenario');
this.reload(); this.reload();
}, },
checkEnv() { checkEnv(val) {
this.$post("/api/automation/checkScenarioEnv", {scenarioDefinition: JSON.stringify(this.scenario), projectId: this.projectId}, res => { this.$post("/api/automation/checkScenarioEnv", {scenarioDefinition: JSON.stringify(this.scenario), projectId: this.projectId}, res => {
if (this.scenario.environmentEnable && !res.data) { if (this.scenario.environmentEnable && !res.data) {
this.scenario.environmentEnable = false; this.scenario.environmentEnable = false;
this.$warning("当前场景没有环境,需要先设置自身环境"); this.$warning("当前场景没有环境,需要先设置自身环境");
return; return;
} }
this.setDomain(); this.setDomain(val);
}); });
}, },
setDomain() { setDomain(val) {
if (this.scenario.environmentEnable) { let param = {
let param = { environmentEnable: val,
environmentEnable: true, id: this.scenario.id,
id: this.scenario.id, environmentType: this.environmentType,
definition: JSON.stringify(this.scenario) environmentGroupId: this.environmentGroupId,
} environmentMap: strMapToObj(this.envMap),
this.$post("/api/automation/setDomain", param, res => { definition: JSON.stringify(this.scenario)
if (res.data) {
let data = JSON.parse(res.data);
this.scenario.hashTree = data.hashTree;
}
})
} }
this.$post("/api/automation/setDomain", param, res => {
if (res.data) {
let data = JSON.parse(res.data);
this.scenario.hashTree = data.hashTree;
}
})
}, },
getCode() { getCode() {
if (this.node && this.node.data.code && this.node.data.debug) { if (this.node && this.node.data.code && this.node.data.debug) {

View File

@ -20,7 +20,7 @@
:title="title" :title="title"
:color="titleColor" :color="titleColor"
:response="response" :response="response"
:environmet-type="environmentType" :environment-type="environmentType"
:environment-group-id="envGroupId" :environment-group-id="envGroupId"
:background-color="backgroundColor" :background-color="backgroundColor"
:project-list="projectList" :project-list="projectList"
@ -34,7 +34,7 @@
@copyRow="copyRow" @copyRow="copyRow"
@refReload="refReload" @refReload="refReload"
@openScenario="openScenario" @openScenario="openScenario"
@setDomain="setDomain"
/> />
</keep-alive> </keep-alive>
</div> </div>
@ -231,6 +231,9 @@ export default {
}, },
stopScenario() { stopScenario() {
this.$emit('stopScenario'); this.$emit('stopScenario');
},
setDomain() {
this.$emit("setDomain");
} }
} }
} }