fix(接口测试): 接口自动化中场景变量添加常量及SQL添加变量,采用mock加函数保存不了,控制台报错

【场景变量添加常量及SQL添加变量,采用mock加函数保存不了,控制台报错】https://www.tapd.cn/33805590/bugtrace/bugs/view?bug_id=1133805590001008481
This commit is contained in:
wxg0103 2021-12-03 11:41:35 +08:00 committed by 刘瑞斌
parent f4e9c82bad
commit 0d680831f6
3 changed files with 47 additions and 7 deletions

View File

@ -24,12 +24,12 @@
value-key="name" value-key="name"
:fetch-suggestions="funcSearch" :fetch-suggestions="funcSearch"
highlight-first-item> highlight-first-item>
<i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced"></i> <i slot="suffix" class="el-input__icon el-icon-edit pointer" @click="advanced(editData.value)"></i>
</el-autocomplete> </el-autocomplete>
</el-col> </el-col>
</el-form-item> </el-form-item>
</el-form> </el-form>
<ms-api-variable-advance ref="variableAdvance"/> <ms-api-variable-advance ref="variableAdvance" :current-item="editData" @advancedRefresh="reload"/>
</div> </div>
</template> </template>
@ -45,11 +45,12 @@
}, },
data() { data() {
return { return {
currentItem: null,
rules: { rules: {
name: [ name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'}, {required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
], ],
}, }
} }
}, },
computed:{ computed:{
@ -58,8 +59,9 @@
} }
}, },
methods: { methods: {
advanced() { advanced(item) {
this.$refs.variableAdvance.open(); this.$refs.variableAdvance.open();
this.editData.value = item;
}, },
createFilter(queryString) { createFilter(queryString) {
return (variable) => { return (variable) => {
@ -77,6 +79,12 @@
// callback // callback
cb(results); cb(results);
}, },
reload() {
this.isActive = false;
this.$nextTick(() => {
this.isActive = true;
});
},
}, },
created() { created() {
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -59,8 +59,10 @@
</el-row> </el-row>
</div> </div>
<ms-api-variable-advance ref="variableAdvance" :environment="environment" :scenario="scenario" <ms-api-variable-advance ref="variableAdvance" :environment="environment" :scenario="scenario"
:append-to-body="appendDialogToBody"
:parameters="parameters" :parameters="parameters"
:current-item="currentItem"/> :current-item="currentItem"
@advancedRefresh="reload"/>
</div> </div>
</template> </template>
@ -84,6 +86,12 @@
type: String, type: String,
default: '' default: ''
}, },
appendDialogToBody: {
type: Boolean,
default() {
return false;
}
},
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
@ -165,7 +173,13 @@
} else { } else {
item.contentType = 'text/plain'; item.contentType = 'text/plain';
} }
} },
reload() {
this.isActive = false;
this.$nextTick(() => {
this.isActive = true;
});
},
}, },
created() { created() {
if (this.parameters.length === 0 || this.parameters[this.parameters.length - 1].name) { if (this.parameters.length === 0 || this.parameters[this.parameters.length - 1].name) {

View File

@ -101,6 +101,12 @@ export default {
environment: Object, environment: Object,
scenario: Scenario, scenario: Scenario,
currentItem: Object, currentItem: Object,
appendToBody: {
type: Boolean,
default() {
return false;
}
},
}, },
data() { data() {
return { return {
@ -161,6 +167,7 @@ export default {
methods: { methods: {
open() { open() {
this.itemValueVisible = true; this.itemValueVisible = true;
this.itemValue = this.currentItem.value;
}, },
prepareData() { prepareData() {
if (this.scenario) { if (this.scenario) {
@ -245,6 +252,11 @@ export default {
this.showPreview(); this.showPreview();
}, },
addFunc() { addFunc() {
if (this.itemValue.indexOf('@') == -1) {
this.itemValue = '@' + this.itemValue;
} else {
this.itemValue = this.itemValue;
}
if (this.mockVariableFuncs.length > 4) { if (this.mockVariableFuncs.length > 4) {
this.$info(this.$t('api_test.request.parameters_advance_add_func_limit')); this.$info(this.$t('api_test.request.parameters_advance_add_func_limit'));
return; return;
@ -267,9 +279,15 @@ export default {
this.mockVariableFuncs.push({name: '', params: []}); this.mockVariableFuncs.push({name: '', params: []});
}, },
saveAdvanced() { saveAdvanced() {
this.currentItem.value = this.itemValue; if (this.itemValue.indexOf('@') == -1) {
this.currentItem.value = '@' + this.itemValue;
} else {
this.currentItem.value = this.itemValue;
}
this.itemValueVisible = false; this.itemValueVisible = false;
this.mockVariableFuncs = []; this.mockVariableFuncs = [];
this.$emit('advancedRefresh', this.currentItem.value);
} }
} }
} }