feat(修改系统参数): mock期望设置响应代码中json-schema增加请求参数的选项

mock期望设置响应代码中json-schema增加请求参数的选项
This commit is contained in:
song-tianyang 2022-02-17 16:56:55 +08:00 committed by LuoTing
parent f26cff3372
commit b9e7250525
6 changed files with 131 additions and 54 deletions

View File

@ -39,7 +39,8 @@
</el-tab-pane> </el-tab-pane>
<!--场景自定义变量--> <!--场景自定义变量-->
<el-tab-pane :label="$t('api_test.automation.scenario_total')" name="variable" v-if="scenarioDefinition != undefined"> <el-tab-pane :label="$t('api_test.automation.scenario_total')" name="variable"
v-if="scenarioDefinition != undefined">
<div> <div>
<el-row style="margin-bottom: 10px"> <el-row style="margin-bottom: 10px">
<div style="float: left"> <div style="float: left">
@ -149,10 +150,12 @@
<div v-for="(item, index) in scenarioPreRequestParams" :key="index" class="kv-row item"> <div v-for="(item, index) in scenarioPreRequestParams" :key="index" class="kv-row item">
<el-row type="flex" :gutter="20" justify="space-between" align="middle"> <el-row type="flex" :gutter="20" justify="space-between" align="middle">
<el-col class="item"> <el-col class="item">
<el-input v-model="item.name" size="small" :readonly="true" @click.native="savePreParams(item.name)"/> <el-input v-model="item.name" size="small" :readonly="true"
@click.native="savePreParams(item.name)"/>
</el-col> </el-col>
<el-col class="item"> <el-col class="item">
<el-input v-model="item.exp" size="small" :readonly="true" @click.native="savePreParams(item.name)"/> <el-input v-model="item.exp" size="small" :readonly="true"
@click.native="savePreParams(item.name)"/>
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
@ -178,6 +181,22 @@
</el-col> </el-col>
</el-row> </el-row>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('api_test.definition.document.request_info')" v-if="showMockVars">
<el-row>
<el-col :span="18" class="col-height">
<div>
<h1>{{ $t('api_test.definition.document.request_info') }}</h1>
<el-table border :data="requestValues"
class="adjust-table table-content"
@row-click="handleRowClick">
<el-table-column prop="type" :label="$t('commons.name')" width="150"/>
<el-table-column prop="name" :label="$t('api_test.value')" width="250"/>
</el-table>
</div>
</el-col>
</el-row>
</el-tab-pane>
</el-tabs> </el-tabs>
<div style="padding-top: 10px;"> <div style="padding-top: 10px;">
<el-row type="flex" align="bottom"> <el-row type="flex" align="bottom">
@ -229,6 +248,12 @@
return false; return false;
} }
}, },
showMockVars: {
type: Boolean,
default() {
return false;
}
},
variables: Array, variables: Array,
scenarioDefinition: Array, scenarioDefinition: Array,
}, },
@ -275,12 +300,41 @@
{name: "number"} {name: "number"}
], ],
mockFuncs: MOCKJS_FUNC.map(f => { mockFuncs: MOCKJS_FUNC.map(f => {
return {name: f.name + " " + f.des + " " + this.$t('api_test.request.parameters_filter_example') + "" + f.ex, value: f.name} return {
name: f.name + " " + f.des + " " + this.$t('api_test.request.parameters_filter_example') + "" + f.ex,
value: f.name
}
}), }),
jmeterFuncs: JMETER_FUNC, jmeterFuncs: JMETER_FUNC,
mockVariableFuncs: [], mockVariableFuncs: [],
jmeterVariableFuncs: [], jmeterVariableFuncs: [],
dialogVisible: true, dialogVisible: true,
requestValues: [
{
type: this.$t('api_test.request.address'),
name: "${address}"
},
{
type: "Header " + this.$t('api_test.definition.document.request_param'),
name: "${header.param}"
},
{
type: this.$t('api_test.request.body') + this.$t('api_test.variable'),
name: "${body.param}"
},
{
type: this.$t('api_test.request.body') + this.$t('api_test.variable') + " (Raw)",
name: "${bodyRaw}"
},
{
type: "Query " + this.$t('api_test.definition.document.request_param'),
name: "${query.param}"
},
{
type: "Rest " + this.$t('api_test.definition.document.request_param'),
name: "${rest.param}"
},
],
// //
defineVariable: "", defineVariable: "",

View File

@ -21,6 +21,7 @@
<ms-json-code-edit <ms-json-code-edit
v-if="body.format==='JSON-SCHEMA'" v-if="body.format==='JSON-SCHEMA'"
:body="body" :body="body"
:show-mock-vars="true"
ref="jsonCodeEdit"/> ref="jsonCodeEdit"/>
<ms-code-edit <ms-code-edit
v-else-if="codeEditActive && loadIsOver" v-else-if="codeEditActive && loadIsOver"

View File

@ -22,7 +22,7 @@
</template> </template>
</el-input> </el-input>
<el-autocomplete :disabled="isReadOnly" v-if="suggestions" v-model="item.name" size="small" <el-autocomplete :disabled="isReadOnly" v-if="suggestions" v-model="item.name" size="small"
:fetch-suggestions="querySearch" @change="change" :placeholder="keyText" show-word-limit> :fetch-suggestions="querySearch" @input="change" @change="change" :placeholder="keyText" show-word-limit>
<template v-slot:prepend> <template v-slot:prepend>
<el-select v-if="type === 'body'" :disabled="isReadOnly" class="kv-type" v-model="item.type" <el-select v-if="type === 'body'" :disabled="isReadOnly" class="kv-type" v-model="item.type"
@change="typeChange(item)"> @change="typeChange(item)">

View File

@ -8,6 +8,7 @@
<div style="min-height: 200px"> <div style="min-height: 200px">
<json-schema-editor class="schema" <json-schema-editor class="schema"
:value="schema" :value="schema"
:show-mock-vars="showMockVars"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
lang="zh_CN" custom/> lang="zh_CN" custom/>
@ -39,6 +40,12 @@
type: Boolean, type: Boolean,
default: true default: true
}, },
showMockVars: {
type: Boolean,
default() {
return false;
}
},
scenarioDefinition: Array, scenarioDefinition: Array,
}, },
created() { created() {

View File

@ -24,6 +24,7 @@
<ms-mock :disabled="pickValue.type==='object' || pickKey ==='root' || pickValue.type==='array' || pickValue.type==='null'" <ms-mock :disabled="pickValue.type==='object' || pickKey ==='root' || pickValue.type==='array' || pickValue.type==='null'"
:schema="pickValue" :schema="pickValue"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
:show-mock-vars="showMockVars"
@editScenarioAdvance="editScenarioAdvance"/> @editScenarioAdvance="editScenarioAdvance"/>
</el-col> </el-col>
<el-col :span="4"> <el-col :span="4">
@ -46,6 +47,7 @@
<json-schema-editor v-for="(item,key,index) in pickValue.properties" :value="{[key]:item}" <json-schema-editor v-for="(item,key,index) in pickValue.properties" :value="{[key]:item}"
:parent="pickValue" :key="index" :deep="deep+1" :root="false" class="children" :parent="pickValue" :key="index" :deep="deep+1" :root="false" class="children"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
:show-mock-vars="showMockVars"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
:lang="lang" :custom="custom" @changeAllItemsType="changeAllItemsType" @reloadItems="reloadItems"/> :lang="lang" :custom="custom" @changeAllItemsType="changeAllItemsType" @reloadItems="reloadItems"/>
</template> </template>
@ -53,6 +55,7 @@
<json-schema-editor v-for="(item,key,index) in pickValue.items" :value="{[key]:item}" :parent="pickValue" :key="index" <json-schema-editor v-for="(item,key,index) in pickValue.items" :value="{[key]:item}" :parent="pickValue" :key="index"
:deep="deep+1" :root="false" class="children" :deep="deep+1" :root="false" class="children"
:scenario-definition="scenarioDefinition" :scenario-definition="scenarioDefinition"
:show-mock-vars="showMockVars"
@editScenarioAdvance="editScenarioAdvance" @editScenarioAdvance="editScenarioAdvance"
:lang="lang" :custom="custom" @changeAllItemsType="changeAllItemsType"/> :lang="lang" :custom="custom" @changeAllItemsType="changeAllItemsType"/>
</template> </template>
@ -108,6 +111,12 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
showMockVars: {
type: Boolean,
default() {
return false;
}
},
disabled: { //namename,name disabled: { //namename,name
type: Boolean, type: Boolean,
default: false default: false

View File

@ -12,7 +12,7 @@
@select="change"> @select="change">
<i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced(mock)"></i> <i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced(mock)"></i>
</el-autocomplete> </el-autocomplete>
<ms-api-variable-advance :scenario-definition="scenarioDefinition" :current-item="mock" ref="variableAdvance"/> <ms-api-variable-advance :show-mock-vars="showMockVars" :scenario-definition="scenarioDefinition" :current-item="mock" ref="variableAdvance"/>
</div> </div>
</template> </template>
@ -32,6 +32,12 @@
}, },
disabled: Boolean, disabled: Boolean,
scenarioDefinition: Array, scenarioDefinition: Array,
showMockVars: {
type: Boolean,
default() {
return false;
}
},
}, },
data() { data() {
return { return {