fix(接口测试): 插件内容显示问题
This commit is contained in:
parent
e9e035c4a1
commit
6a2bf297a3
|
@ -179,6 +179,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Vue from 'vue';
|
||||||
import ApiBaseComponent from '../common/ApiBaseComponent';
|
import ApiBaseComponent from '../common/ApiBaseComponent';
|
||||||
import ApiResponseComponent from './ApiResponseComponent';
|
import ApiResponseComponent from './ApiResponseComponent';
|
||||||
import formCreate from '@form-create/element-ui';
|
import formCreate from '@form-create/element-ui';
|
||||||
|
@ -196,6 +197,7 @@ const store = useApiStore();
|
||||||
formCreate.component('msUpload', MsUpload);
|
formCreate.component('msUpload', MsUpload);
|
||||||
formCreate.component('msPluginContentAssertions', MsPluginContentAssertions);
|
formCreate.component('msPluginContentAssertions', MsPluginContentAssertions);
|
||||||
|
|
||||||
|
Vue.use(formCreate);
|
||||||
export default {
|
export default {
|
||||||
name: 'PluginComponent',
|
name: 'PluginComponent',
|
||||||
components: {
|
components: {
|
||||||
|
@ -368,7 +370,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
run() {
|
run() {
|
||||||
if(this.request.plugin_del){
|
if (this.request.plugin_del) {
|
||||||
this.$error(this.$t('automation.scenario_plugin_save_warning'));
|
this.$error(this.$t('automation.scenario_plugin_save_warning'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,32 @@
|
||||||
<template>
|
<template>
|
||||||
<ms-drawer class="json-path-picker" :visible="visible" :size="30" @close="close" direction="right"
|
<ms-drawer
|
||||||
v-clickoutside="close">
|
class="json-path-picker"
|
||||||
|
:visible="visible"
|
||||||
|
:size="30"
|
||||||
|
@close="close"
|
||||||
|
direction="right"
|
||||||
|
v-clickoutside="close"
|
||||||
|
>
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<ms-instructions-icon :content="tip"/>
|
<ms-instructions-icon :content="tip" />
|
||||||
{{ tip }}
|
{{ tip }}
|
||||||
</template>
|
</template>
|
||||||
<jsonpath-picker :code="data" v-on:path="pathChangeHandler" ref="jsonpathPicker"/>
|
<jsonpath-picker
|
||||||
|
:code="data"
|
||||||
|
v-on:path="pathChangeHandler"
|
||||||
|
ref="jsonpathPicker"
|
||||||
|
/>
|
||||||
</ms-drawer>
|
</ms-drawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Vue from "vue";
|
||||||
|
import JsonPathPicker from "vue-jsonpath-picker";
|
||||||
import MsDrawer from "../../MsDrawer";
|
import MsDrawer from "../../MsDrawer";
|
||||||
import MsInstructionsIcon from "../../MsInstructionsIcon";
|
import MsInstructionsIcon from "../../MsInstructionsIcon";
|
||||||
|
|
||||||
|
Vue.use(JsonPathPicker);
|
||||||
|
|
||||||
let dotReplace = "#DOT_MASK#";
|
let dotReplace = "#DOT_MASK#";
|
||||||
|
|
||||||
const clickoutside = {
|
const clickoutside = {
|
||||||
|
@ -21,32 +35,31 @@ const clickoutside = {
|
||||||
function documentHandler(e) {
|
function documentHandler(e) {
|
||||||
// 这里判断点击的元素是否是本身,是本身,则返回
|
// 这里判断点击的元素是否是本身,是本身,则返回
|
||||||
if (el.contains(e.target)) {
|
if (el.contains(e.target)) {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
// 判断指令中是否绑定了函数
|
// 判断指令中是否绑定了函数
|
||||||
if (binding.expression) {
|
if (binding.expression) {
|
||||||
// 如果绑定了函数 则调用那个函数,此处binding.value就是handleClose方法
|
// 如果绑定了函数 则调用那个函数,此处binding.value就是handleClose方法
|
||||||
binding.value(e)
|
binding.value(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 给当前元素绑定个私有变量,方便在unbind中可以解除事件监听
|
// 给当前元素绑定个私有变量,方便在unbind中可以解除事件监听
|
||||||
el.__vueClickOutside__ = documentHandler
|
el.__vueClickOutside__ = documentHandler;
|
||||||
document.addEventListener('click', documentHandler)
|
document.addEventListener("click", documentHandler);
|
||||||
},
|
|
||||||
update() {
|
|
||||||
},
|
},
|
||||||
|
update() {},
|
||||||
unbind(el, binding) {
|
unbind(el, binding) {
|
||||||
// 解除事件监听
|
// 解除事件监听
|
||||||
document.removeEventListener('click', el.__vueClickOutside__)
|
document.removeEventListener("click", el.__vueClickOutside__);
|
||||||
delete el.__vueClickOutside__
|
delete el.__vueClickOutside__;
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MsApiJsonpathSuggest",
|
name: "MsApiJsonpathSuggest",
|
||||||
components: {MsInstructionsIcon, MsDrawer},
|
components: { MsInstructionsIcon, MsDrawer },
|
||||||
directives: {clickoutside},
|
directives: { clickoutside },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
visible: false,
|
visible: false,
|
||||||
|
@ -58,8 +71,8 @@ export default {
|
||||||
tip: {
|
tip: {
|
||||||
type: String,
|
type: String,
|
||||||
default() {
|
default() {
|
||||||
return ""
|
return "";
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -69,9 +82,12 @@ export default {
|
||||||
open(objStr) {
|
open(objStr) {
|
||||||
this.data = {};
|
this.data = {};
|
||||||
try {
|
try {
|
||||||
let stringedJSON = objStr.replace(/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g, '"$1"');
|
let stringedJSON = objStr.replace(
|
||||||
|
/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g,
|
||||||
|
'"$1"'
|
||||||
|
);
|
||||||
let param;
|
let param;
|
||||||
let JSONBig = require('json-bigint')({"storeAsString": true});
|
let JSONBig = require("json-bigint")({ storeAsString: true });
|
||||||
// 解决精度丢失问题
|
// 解决精度丢失问题
|
||||||
try {
|
try {
|
||||||
param = JSON.parse(JSON.stringify(JSONBig.parse(stringedJSON)));
|
param = JSON.parse(JSON.stringify(JSONBig.parse(stringedJSON)));
|
||||||
|
@ -79,12 +95,12 @@ export default {
|
||||||
param = JSON.parse(JSON.stringify(JSONBig.parse(objStr)));
|
param = JSON.parse(JSON.stringify(JSONBig.parse(objStr)));
|
||||||
}
|
}
|
||||||
if (param instanceof Array) {
|
if (param instanceof Array) {
|
||||||
this.$warning('不支持解析JSON数组');
|
this.$warning("不支持解析JSON数组");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.data = param;
|
this.data = param;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.$warning(this.$t('api_test.request.assertions.json_path_err'));
|
this.$warning(this.$t("api_test.request.assertions.json_path_err"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
|
@ -97,10 +113,10 @@ export default {
|
||||||
result = this.getParamValue(this.data, 0, paramNames);
|
result = this.getParamValue(this.data, 0, paramNames);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result = {};
|
result = {};
|
||||||
result.key = 'var';
|
result.key = "var";
|
||||||
}
|
}
|
||||||
result.path = '$.' + data;
|
result.path = "$." + data;
|
||||||
this.$emit('addSuggest', result);
|
this.$emit("addSuggest", result);
|
||||||
},
|
},
|
||||||
// 替换. 等特殊字符
|
// 替换. 等特殊字符
|
||||||
parseSpecialChar(data) {
|
parseSpecialChar(data) {
|
||||||
|
@ -108,22 +124,22 @@ export default {
|
||||||
let reg = /\['.*'\]/;
|
let reg = /\['.*'\]/;
|
||||||
let searchStr = reg.exec(data);
|
let searchStr = reg.exec(data);
|
||||||
if (searchStr) {
|
if (searchStr) {
|
||||||
searchStr.forEach(item => {
|
searchStr.forEach((item) => {
|
||||||
if (data.startsWith("['")) {
|
if (data.startsWith("['")) {
|
||||||
data = data.replace(item, item.replace('.', dotReplace));
|
data = data.replace(item, item.replace(".", dotReplace));
|
||||||
} else {
|
} else {
|
||||||
data = data.replace(item, '.' + item.replace('.', dotReplace));
|
data = data.replace(item, "." + item.replace(".", dotReplace));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
paramNames = data.split('.');
|
paramNames = data.split(".");
|
||||||
} else {
|
} else {
|
||||||
paramNames = data.split('.');
|
paramNames = data.split(".");
|
||||||
}
|
}
|
||||||
for (let i in paramNames) {
|
for (let i in paramNames) {
|
||||||
if (paramNames[i].search(reg) > -1) {
|
if (paramNames[i].search(reg) > -1) {
|
||||||
paramNames[i] = paramNames[i].substring(2, paramNames[i].length - 2);
|
paramNames[i] = paramNames[i].substring(2, paramNames[i].length - 2);
|
||||||
}
|
}
|
||||||
paramNames[i] = paramNames[i].replace(dotReplace, '.');
|
paramNames[i] = paramNames[i].replace(dotReplace, ".");
|
||||||
}
|
}
|
||||||
return paramNames;
|
return paramNames;
|
||||||
},
|
},
|
||||||
|
@ -153,18 +169,17 @@ export default {
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
key: param,
|
key: param,
|
||||||
value: childObj
|
value: childObj,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
return this.getParamValue(childObj, index, params);
|
return this.getParamValue(childObj, index, params);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
.json-path-picker {
|
.json-path-picker {
|
||||||
padding: 10px 13px;
|
padding: 10px 13px;
|
||||||
}
|
}
|
||||||
|
@ -178,5 +193,4 @@ export default {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue