fix(接口测试): 插件内容显示问题

This commit is contained in:
baiqi 2023-07-18 15:04:04 +08:00 committed by fit2-zhao
parent e9e035c4a1
commit 6a2bf297a3
2 changed files with 54 additions and 38 deletions

View File

@ -179,6 +179,7 @@
</template>
<script>
import Vue from 'vue';
import ApiBaseComponent from '../common/ApiBaseComponent';
import ApiResponseComponent from './ApiResponseComponent';
import formCreate from '@form-create/element-ui';
@ -196,6 +197,7 @@ const store = useApiStore();
formCreate.component('msUpload', MsUpload);
formCreate.component('msPluginContentAssertions', MsPluginContentAssertions);
Vue.use(formCreate);
export default {
name: 'PluginComponent',
components: {

View File

@ -1,18 +1,32 @@
<template>
<ms-drawer class="json-path-picker" :visible="visible" :size="30" @close="close" direction="right"
v-clickoutside="close">
<ms-drawer
class="json-path-picker"
:visible="visible"
:size="30"
@close="close"
direction="right"
v-clickoutside="close"
>
<template v-slot:header>
<ms-instructions-icon :content="tip" />
{{ tip }}
</template>
<jsonpath-picker :code="data" v-on:path="pathChangeHandler" ref="jsonpathPicker"/>
<jsonpath-picker
:code="data"
v-on:path="pathChangeHandler"
ref="jsonpathPicker"
/>
</ms-drawer>
</template>
<script>
import Vue from "vue";
import JsonPathPicker from "vue-jsonpath-picker";
import MsDrawer from "../../MsDrawer";
import MsInstructionsIcon from "../../MsInstructionsIcon";
Vue.use(JsonPathPicker);
let dotReplace = "#DOT_MASK#";
const clickoutside = {
@ -21,27 +35,26 @@ const clickoutside = {
function documentHandler(e) {
//
if (el.contains(e.target)) {
return false
return false;
}
//
if (binding.expression) {
// binding.valuehandleClose
binding.value(e)
binding.value(e);
}
}
// 便unbind
el.__vueClickOutside__ = documentHandler
document.addEventListener('click', documentHandler)
},
update() {
el.__vueClickOutside__ = documentHandler;
document.addEventListener("click", documentHandler);
},
update() {},
unbind(el, binding) {
//
document.removeEventListener('click', el.__vueClickOutside__)
delete el.__vueClickOutside__
}
}
document.removeEventListener("click", el.__vueClickOutside__);
delete el.__vueClickOutside__;
},
};
export default {
name: "MsApiJsonpathSuggest",
@ -58,8 +71,8 @@ export default {
tip: {
type: String,
default() {
return ""
}
return "";
},
},
},
methods: {
@ -69,9 +82,12 @@ export default {
open(objStr) {
this.data = {};
try {
let stringedJSON = objStr.replace(/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g, '"$1"');
let stringedJSON = objStr.replace(
/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g,
'"$1"'
);
let param;
let JSONBig = require('json-bigint')({"storeAsString": true});
let JSONBig = require("json-bigint")({ storeAsString: true });
//
try {
param = JSON.parse(JSON.stringify(JSONBig.parse(stringedJSON)));
@ -79,12 +95,12 @@ export default {
param = JSON.parse(JSON.stringify(JSONBig.parse(objStr)));
}
if (param instanceof Array) {
this.$warning('不支持解析JSON数组');
this.$warning("不支持解析JSON数组");
return;
}
this.data = param;
} 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;
}
this.visible = true;
@ -97,10 +113,10 @@ export default {
result = this.getParamValue(this.data, 0, paramNames);
} catch (e) {
result = {};
result.key = 'var';
result.key = "var";
}
result.path = '$.' + data;
this.$emit('addSuggest', result);
result.path = "$." + data;
this.$emit("addSuggest", result);
},
// .
parseSpecialChar(data) {
@ -108,22 +124,22 @@ export default {
let reg = /\['.*'\]/;
let searchStr = reg.exec(data);
if (searchStr) {
searchStr.forEach(item => {
searchStr.forEach((item) => {
if (data.startsWith("['")) {
data = data.replace(item, item.replace('.', dotReplace));
data = data.replace(item, item.replace(".", dotReplace));
} else {
data = data.replace(item, '.' + item.replace('.', dotReplace));
data = data.replace(item, "." + item.replace(".", dotReplace));
}
});
paramNames = data.split('.');
paramNames = data.split(".");
} else {
paramNames = data.split('.');
paramNames = data.split(".");
}
for (let i in paramNames) {
if (paramNames[i].search(reg) > -1) {
paramNames[i] = paramNames[i].substring(2, paramNames[i].length - 2);
}
paramNames[i] = paramNames[i].replace(dotReplace, '.');
paramNames[i] = paramNames[i].replace(dotReplace, ".");
}
return paramNames;
},
@ -153,18 +169,17 @@ export default {
}
return {
key: param,
value: childObj
value: childObj,
};
}
index++;
return this.getParamValue(childObj, index, params);
}
}
}
},
},
};
</script>
<style scoped>
.json-path-picker {
padding: 10px 13px;
}
@ -178,5 +193,4 @@ export default {
font-size: 30px;
font-weight: bold;
}
</style>