feat: 高级参数设置前端实现
This commit is contained in:
parent
fa13003865
commit
9d6c1ea86d
|
@ -85,8 +85,7 @@
|
|||
<script>
|
||||
import {KeyValue} from "../model/ScenarioModel";
|
||||
import {MOCKJS_FUNC} from "@/common/js/constants";
|
||||
import Mock from "mockjs";
|
||||
import {funcFilters} from "@/common/js/func-filter";
|
||||
import {calculate} from "@/business/components/api/test/model/ScenarioModel";
|
||||
|
||||
export default {
|
||||
name: "MsApiKeyValue",
|
||||
|
@ -171,30 +170,7 @@ export default {
|
|||
};
|
||||
},
|
||||
showPreview(itemValue) {
|
||||
if (!itemValue) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let funcs = itemValue.split("|");
|
||||
let value = Mock.mock(funcs[0].trim());
|
||||
if (funcs.length === 1) {
|
||||
this.itemValuePreview = value;
|
||||
return value;
|
||||
}
|
||||
for (let i = 1; i < funcs.length; i++) {
|
||||
let func = funcs[i].trim();
|
||||
let args = func.split(":");
|
||||
let strings = [];
|
||||
if (args[1]) {
|
||||
strings = args[1].split(",");
|
||||
}
|
||||
value = funcFilters[args[0].trim()](value, ...strings);
|
||||
}
|
||||
this.itemValuePreview = value;
|
||||
return value;
|
||||
} catch (e) {
|
||||
this.itemValuePreview = itemValue;
|
||||
}
|
||||
this.itemValuePreview = calculate(itemValue);
|
||||
},
|
||||
appendFunc(func) {
|
||||
if (this.itemValue) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
Arguments, CookieManager,
|
||||
Arguments,
|
||||
CookieManager,
|
||||
DubboSample,
|
||||
DurationAssertion,
|
||||
Element,
|
||||
|
@ -18,6 +19,8 @@ import {
|
|||
ThreadGroup,
|
||||
XPath2Extractor,
|
||||
} from "./JMX";
|
||||
import Mock from "mockjs";
|
||||
import {funcFilters} from "@/common/js/func-filter";
|
||||
|
||||
export const uuid = function () {
|
||||
let d = new Date().getTime()
|
||||
|
@ -35,6 +38,31 @@ export const uuid = function () {
|
|||
});
|
||||
}
|
||||
|
||||
export const calculate = function (itemValue) {
|
||||
if (!itemValue) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let funcs = itemValue.split("|");
|
||||
let value = Mock.mock(funcs[0].trim());
|
||||
if (funcs.length === 1) {
|
||||
return value;
|
||||
}
|
||||
for (let i = 1; i < funcs.length; i++) {
|
||||
let func = funcs[i].trim();
|
||||
let args = func.split(":");
|
||||
let strings = [];
|
||||
if (args[1]) {
|
||||
strings = args[1].split(",");
|
||||
}
|
||||
value = funcFilters[args[0].trim()](value, ...strings);
|
||||
}
|
||||
return value;
|
||||
} catch (e) {
|
||||
return itemValue;
|
||||
}
|
||||
}
|
||||
|
||||
export const BODY_TYPE = {
|
||||
KV: "KeyValue",
|
||||
FORM_DATA: "Form Data",
|
||||
|
@ -885,6 +913,9 @@ class JMXGenerator {
|
|||
|
||||
addRequestArguments(httpSamplerProxy, request) {
|
||||
let args = this.filterKV(request.parameters);
|
||||
args.forEach(arg => {
|
||||
arg.value = calculate(arg.value);
|
||||
});
|
||||
if (args.length > 0) {
|
||||
httpSamplerProxy.add(new HTTPSamplerArguments(args));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue