style(接口测试): 规范化提交内容

This commit is contained in:
fit2-zhao 2020-09-03 16:17:15 +08:00
parent 82cf5b25c4
commit 60961c0a27
5 changed files with 263 additions and 258 deletions

View File

@ -12,7 +12,8 @@ public class KeyValue {
private String type; private String type;
private List<BodyFile> files; private List<BodyFile> files;
private String description; private String description;
private boolean checked; private boolean enable;
public KeyValue() { public KeyValue() {
} }

View File

@ -6,7 +6,8 @@
<div class="kv-row" v-for="(item, index) in items" :key="index"> <div class="kv-row" v-for="(item, index) in items" :key="index">
<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="kv-checkbox"> <el-col class="kv-checkbox">
<input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues" :disabled="isDisable(index) || isReadOnly"/> <input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues"
:disabled="isDisable(index) || isReadOnly"/>
</el-col> </el-col>
<el-col> <el-col>
@ -32,122 +33,123 @@
</template> </template>
<script> <script>
import {KeyValue} from "../model/ScenarioModel"; import {KeyValue} from "../model/ScenarioModel";
export default { export default {
name: "MsApiKeyValue", name: "MsApiKeyValue",
props: { props: {
keyPlaceholder: String, keyPlaceholder: String,
valuePlaceholder: String, valuePlaceholder: String,
description: String, description: String,
items: Array, items: Array,
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
},
suggestions: Array
}, },
suggestions: Array data() {
}, return {
data() { checkedValues: []
return {
checkedValues:[]
}
},
computed: {
keyText() {
return this.keyPlaceholder || this.$t("api_test.key");
},
valueText() {
return this.valuePlaceholder || this.$t("api_test.value");
}
},
methods: {
remove: function (index) {
//
let checkIndex = this.checkedValues.indexOf(this.items[index].uuid);
checkIndex != -1 ? this.checkedValues.splice(checkIndex,1): this.checkedValues;
//
this.items.splice(index, 1);
this.$emit('change', this.items);
},
change: function () {
let isNeedCreate = true;
let removeIndex = -1;
this.items.forEach((item, index) => {
//
item.checked=this.checkedValues.indexOf(item.uuid) != -1 ? true:false;
if (!item.name && !item.value) {
//
if (index !== this.items.length - 1) {
removeIndex = index;
}
//
isNeedCreate = false;
}
});
if (isNeedCreate) {
//
this.items[this.items.length-1].checked = true;
// v-model
this.checkedValues.push(this.items[this.items.length-1].uuid);
this.items.push(new KeyValue());
} }
this.$emit('change', this.items);
// TODO key
}, },
isDisable: function (index) { computed: {
return this.items.length - 1 === index; keyText() {
return this.keyPlaceholder || this.$t("api_test.key");
},
valueText() {
return this.valuePlaceholder || this.$t("api_test.value");
}
}, },
querySearch(queryString, cb) {
let suggestions = this.suggestions; methods: {
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions; remove: function (index) {
cb(results); //
}, let checkIndex = this.checkedValues.indexOf(this.items[index].uuid);
uuid: function () { checkIndex != -1 ? this.checkedValues.splice(checkIndex, 1) : this.checkedValues;
return (((1+Math.random())*0x100000)|0).toString(16).substring(1); //
}, this.items.splice(index, 1);
createFilter(queryString) { this.$emit('change', this.items);
return (restaurant) => { },
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0); change: function () {
}; let isNeedCreate = true;
}, let removeIndex = -1;
}, this.items.forEach((item, index) => {
created() { //
if (this.items.length === 0) { item.enable = this.checkedValues.indexOf(item.uuid) != -1 ? true : false;
this.items.push(new KeyValue());
}else{ if (!item.name && !item.value) {
this.items.forEach((item, index) => { //
let uuid = this.uuid(); if (index !== this.items.length - 1) {
item.uuid = uuid; removeIndex = index;
if(item.checked){ }
this.checkedValues.push(uuid); //
isNeedCreate = false;
}
});
if (isNeedCreate) {
//
this.items[this.items.length - 1].enable = true;
// v-model
this.checkedValues.push(this.items[this.items.length - 1].uuid);
this.items.push(new KeyValue());
} }
}) this.$emit('change', this.items);
// TODO key
},
isDisable: function (index) {
return this.items.length - 1 === index;
},
querySearch(queryString, cb) {
let suggestions = this.suggestions;
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions;
cb(results);
},
uuid: function () {
return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
};
},
},
created() {
if (this.items.length === 0) {
this.items.push(new KeyValue());
} else {
this.items.forEach((item, index) => {
let uuid = this.uuid();
item.uuid = uuid;
if (item.enable) {
this.checkedValues.push(uuid);
}
})
}
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.kv-description { .kv-description {
font-size: 13px; font-size: 13px;
} }
.kv-row { .kv-row {
margin-top: 10px; margin-top: 10px;
} }
.kv-checkbox {
width: 20px;
margin-right: 10px;
}
.kv-delete { .kv-checkbox {
width: 60px; width: 20px;
} margin-right: 10px;
}
.el-autocomplete { .kv-delete {
width: 100%; width: 60px;
} }
.el-autocomplete {
width: 100%;
}
</style> </style>

View File

@ -7,7 +7,8 @@
<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="kv-checkbox"> <el-col class="kv-checkbox">
<input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues" :disabled="isDisable(index) || isReadOnly"/> <input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="checkedValues"
:disabled="isDisable(index) || isReadOnly"/>
</el-col> </el-col>
<el-col> <el-col>
@ -56,166 +57,167 @@
</template> </template>
<script> <script>
import {KeyValue, Scenario} from "../model/ScenarioModel"; import {KeyValue, Scenario} from "../model/ScenarioModel";
import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants"; import {JMETER_FUNC, MOCKJS_FUNC} from "@/common/js/constants";
import MsApiVariableAdvance from "@/business/components/api/test/components/ApiVariableAdvance"; import MsApiVariableAdvance from "@/business/components/api/test/components/ApiVariableAdvance";
import MsApiBodyFileUpload from "./body/ApiBodyFileUpload"; import MsApiBodyFileUpload from "./body/ApiBodyFileUpload";
export default { export default {
name: "MsApiVariable", name: "MsApiVariable",
components: {MsApiBodyFileUpload, MsApiVariableAdvance}, components: {MsApiBodyFileUpload, MsApiVariableAdvance},
props: { props: {
keyPlaceholder: String, keyPlaceholder: String,
valuePlaceholder: String, valuePlaceholder: String,
description: String, description: String,
parameters: Array, parameters: Array,
environment: Object, environment: Object,
scenario: Scenario, scenario: Scenario,
type: { type: {
type: String, type: String,
default: '' default: ''
},
isReadOnly: {
type: Boolean,
default: false
},
suggestions: Array
}, },
isReadOnly: { data() {
type: Boolean, return {
default: false currentItem: null,
}, checkedValues: []
suggestions: Array
},
data() {
return {
currentItem: null,
checkedValues:[]
}
},
computed: {
keyText() {
return this.keyPlaceholder || this.$t("api_test.key");
},
valueText() {
return this.valuePlaceholder || this.$t("api_test.value");
}
},
methods: {
remove: function (index) {
//
let checkIndex = this.checkedValues.indexOf(this.parameters[index].uuid);
checkIndex != -1 ? this.checkedValues.splice(checkIndex,1): this.checkedValues;
//
this.parameters.splice(index, 1);
this.$emit('change', this.parameters);
},
change: function () {
let isNeedCreate = true;
let removeIndex = -1;
this.parameters.forEach((item, index) => {
//
item.checked=this.checkedValues.indexOf(item.uuid) != -1 ? true:false;
if (!item.name && !item.value) {
//
if (index !== this.parameters.length - 1) {
removeIndex = index;
}
//
isNeedCreate = false;
}
});
if (isNeedCreate) {
//
this.parameters[this.parameters.length-1].checked = true;
// v-model
this.checkedValues.push(this.parameters[this.parameters.length-1].uuid);
this.parameters.push(new KeyValue(null, null, 'text',false,this.uuid()));
} }
this.$emit('change', this.parameters);
// TODO key
}, },
isDisable: function (index) { computed: {
return this.parameters.length - 1 === index; keyText() {
}, return this.keyPlaceholder || this.$t("api_test.key");
querySearch(queryString, cb) { },
let suggestions = this.suggestions; valueText() {
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions; return this.valuePlaceholder || this.$t("api_test.value");
cb(results); }
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
};
},
funcSearch(queryString, cb) {
let funcs = MOCKJS_FUNC.concat(JMETER_FUNC);
let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs;
// callback
cb(results);
},
funcFilter(queryString) {
return (func) => {
return (func.name.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
};
},
uuid: function () {
return (((1+Math.random())*0x100000)|0).toString(16).substring(1);
},
advanced(item) {
this.$refs.variableAdvance.open();
this.currentItem = item;
this.itemValue = '';
this.mockVariableFuncs = [];
}, },
methods: {
remove: function (index) {
//
let checkIndex = this.checkedValues.indexOf(this.parameters[index].uuid);
checkIndex != -1 ? this.checkedValues.splice(checkIndex, 1) : this.checkedValues;
//
this.parameters.splice(index, 1);
this.$emit('change', this.parameters);
},
change: function () {
let isNeedCreate = true;
let removeIndex = -1;
this.parameters.forEach((item, index) => {
//
item.enable = this.checkedValues.indexOf(item.uuid) != -1 ? true : false;
}, if (!item.name && !item.value) {
created() { //
if (this.parameters.length === 0) { if (index !== this.parameters.length - 1) {
this.parameters.push(new KeyValue(null, null, 'text',false,this.uuid())); removeIndex = index;
}else{ }
this.parameters.forEach((item, index) => { //
let uuid = this.uuid(); isNeedCreate = false;
item.uuid = uuid; }
if(item.checked){ });
this.checkedValues.push(uuid); if (isNeedCreate) {
//
this.parameters[this.parameters.length - 1].enable = true;
// v-model
this.checkedValues.push(this.parameters[this.parameters.length - 1].uuid);
this.parameters.push(new KeyValue(null, null, 'text', false, this.uuid()));
} }
}) this.$emit('change', this.parameters);
// TODO key
},
isDisable: function (index) {
return this.parameters.length - 1 === index;
},
querySearch(queryString, cb) {
let suggestions = this.suggestions;
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions;
cb(results);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
};
},
funcSearch(queryString, cb) {
let funcs = MOCKJS_FUNC.concat(JMETER_FUNC);
let results = queryString ? funcs.filter(this.funcFilter(queryString)) : funcs;
// callback
cb(results);
},
funcFilter(queryString) {
return (func) => {
return (func.name.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
};
},
uuid: function () {
return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
},
advanced(item) {
this.$refs.variableAdvance.open();
this.currentItem = item;
this.itemValue = '';
this.mockVariableFuncs = [];
},
},
created() {
if (this.parameters.length === 0) {
this.parameters.push(new KeyValue(null, null, 'text', false, this.uuid()));
} else {
this.parameters.forEach((item, index) => {
let uuid = this.uuid();
item.uuid = uuid;
if (item.enable) {
this.checkedValues.push(uuid);
}
})
}
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.kv-description { .kv-description {
font-size: 13px; font-size: 13px;
} }
.kv-row { .kv-row {
margin-top: 10px; margin-top: 10px;
} }
.kv-delete { .kv-delete {
width: 60px; width: 60px;
} }
.el-autocomplete { .el-autocomplete {
width: 100%; width: 100%;
} }
.kv-checkbox {
width: 20px;
margin-right: 10px;
}
.advanced-item-value >>> .el-dialog__body { .kv-checkbox {
padding: 15px 25px; width: 20px;
} margin-right: 10px;
}
.el-row { .advanced-item-value >>> .el-dialog__body {
margin-bottom: 5px; padding: 15px 25px;
} }
.kv-type { .el-row {
width: 70px; margin-bottom: 5px;
} }
.pointer { .kv-type {
cursor: pointer; width: 70px;
color: #1E90FF; }
}
.pointer {
cursor: pointer;
color: #1E90FF;
}
</style> </style>

View File

@ -318,7 +318,7 @@ export class HTTPSamplerArguments extends Element {
let collectionProp = this.collectionProp('Arguments.arguments'); let collectionProp = this.collectionProp('Arguments.arguments');
this.args.forEach(arg => { this.args.forEach(arg => {
if(arg.checked) { // 非禁用的条件加入执行 if (arg.enable) { // 非禁用的条件加入执行
let elementProp = collectionProp.elementProp(arg.name, 'HTTPArgument'); let elementProp = collectionProp.elementProp(arg.name, 'HTTPArgument');
elementProp.boolProp('HTTPArgument.always_encode', arg.encode, true); elementProp.boolProp('HTTPArgument.always_encode', arg.encode, true);
elementProp.boolProp('HTTPArgument.use_equals', arg.equals, true); elementProp.boolProp('HTTPArgument.use_equals', arg.equals, true);
@ -490,7 +490,7 @@ export class HeaderManager extends DefaultTestElement {
this.headers.forEach(header => { this.headers.forEach(header => {
let elementProp = collectionProp.elementProp('', 'Header'); let elementProp = collectionProp.elementProp('', 'Header');
if(header.checked) { if (header.enable) {
elementProp.stringProp('Header.name', header.name); elementProp.stringProp('Header.name', header.name);
elementProp.stringProp('Header.value', header.value); elementProp.stringProp('Header.value', header.value);
} }
@ -506,7 +506,7 @@ export class Arguments extends DefaultTestElement {
let collectionProp = this.collectionProp('Arguments.arguments'); let collectionProp = this.collectionProp('Arguments.arguments');
this.args.forEach(arg => { this.args.forEach(arg => {
if(arg.checked) { // 非禁用的条件加入执行 if (arg.enable) { // 非禁用的条件加入执行
let elementProp = collectionProp.elementProp(arg.name, 'Argument'); let elementProp = collectionProp.elementProp(arg.name, 'Argument');
elementProp.stringProp('Argument.name', arg.name); elementProp.stringProp('Argument.name', arg.name);
elementProp.stringProp('Argument.value', arg.value); elementProp.stringProp('Argument.value', arg.value);
@ -531,7 +531,7 @@ export class ElementArguments extends Element {
let collectionProp = this.collectionProp('Arguments.arguments'); let collectionProp = this.collectionProp('Arguments.arguments');
if (args) { if (args) {
args.forEach(arg => { args.forEach(arg => {
if(arg.checked) { // 非禁用的条件加入执行 if (arg.enable) { // 非禁用的条件加入执行
let elementProp = collectionProp.elementProp(arg.name, 'Argument'); let elementProp = collectionProp.elementProp(arg.name, 'Argument');
elementProp.stringProp('Argument.name', arg.name); elementProp.stringProp('Argument.name', arg.name);
elementProp.stringProp('Argument.value', arg.value); elementProp.stringProp('Argument.value', arg.value);

View File

@ -312,7 +312,7 @@ export class HttpRequest extends Request {
this.jsr223PreProcessor = undefined; this.jsr223PreProcessor = undefined;
this.jsr223PostProcessor = undefined; this.jsr223PostProcessor = undefined;
this.enable = true; this.enable = true;
this.connectTimeout = 60*1000; this.connectTimeout = 60 * 1000;
this.responseTimeout = undefined; this.responseTimeout = undefined;
this.followRedirects = true; this.followRedirects = true;
@ -541,7 +541,7 @@ export class Body extends BaseConfig {
export class KeyValue extends BaseConfig { export class KeyValue extends BaseConfig {
constructor() { constructor() {
let options, key, value, type,checked,uuid; let options, key, value, type, enable, uuid;
if (arguments.length === 1) { if (arguments.length === 1) {
options = arguments[0]; options = arguments[0];
} }
@ -559,7 +559,7 @@ export class KeyValue extends BaseConfig {
key = arguments[0]; key = arguments[0];
value = arguments[1]; value = arguments[1];
type = arguments[2]; type = arguments[2];
checked = arguments[3]; enable = arguments[3];
uuid = arguments[4]; uuid = arguments[4];
} }
super(); super();
@ -567,7 +567,7 @@ export class KeyValue extends BaseConfig {
this.value = value; this.value = value;
this.type = type; this.type = type;
this.files = undefined; this.files = undefined;
this.checked = checked; this.enable = enable;
this.uuid = uuid; this.uuid = uuid;
this.set(options); this.set(options);
} }
@ -780,7 +780,7 @@ class JMXHttpRequest {
if (this.method.toUpperCase() !== "GET") { if (this.method.toUpperCase() !== "GET") {
let parameters = []; let parameters = [];
request.parameters.forEach(parameter => { request.parameters.forEach(parameter => {
if (parameter.name && parameter.value && parameter.checked) { if (parameter.name && parameter.value && parameter.enable) {
parameters.push(parameter); parameters.push(parameter);
} }
}); });