fix: jsonpath 推荐名字中带有'.',推荐失败

This commit is contained in:
chenjianxing 2021-02-04 15:50:28 +08:00
parent 7955dc6205
commit ef3ddf4a8a
2 changed files with 57 additions and 24 deletions

View File

@ -9,27 +9,28 @@
</template>
<script>
import MsDrawer from "../../../../common/components/MsDrawer";
import MsInstructionsIcon from "../../../../common/components/MsInstructionsIcon";
import MsDrawer from "../../../../common/components/MsDrawer";
import MsInstructionsIcon from "../../../../common/components/MsInstructionsIcon";
export default {
name: "MsApiJsonpathSuggest",
components: {MsInstructionsIcon, MsDrawer},
data() {
return {
visible: false,
isCheckAll: false,
data: {},
};
},
props: {
tip: {
type: String,
default() {
return ""
}
},
let dotReplace = "#DOT_MASK#";
export default {
name: "MsApiJsonpathSuggest",
components: {MsInstructionsIcon, MsDrawer},
data() {
return {
visible: false,
isCheckAll: false,
data: {},
};
},
props: {
tip: {
type: String,
default() {
return ""
}
},
},
methods: {
close() {
this.visible = false;
@ -50,14 +51,46 @@
this.visible = true;
},
pathChangeHandler(data) {
let paramNames = data.split('.');
let result = this.getParamValue(this.data, 0, paramNames);
let paramNames = [];
let result = {};
try {
paramNames = this.parseSpecialChar(data);
result = this.getParamValue(this.data, 0, paramNames);
} catch (e) {
result = {};
result.key = 'var';
}
result.path = '$.' + data;
this.$emit('addSuggest', result);
},
// .
parseSpecialChar(data) {
let paramNames = [];
let reg = /\['.*'\]/;
let searchStr = reg.exec(data);
if (searchStr) {
searchStr.forEach(item => {
if (data.startsWith("['")) {
data = data.replace(item, item.replace('.', dotReplace));
} else {
data = data.replace(item, '.' + item.replace('.', dotReplace));
}
});
paramNames = data.split('.');
} else {
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, '.');
}
return paramNames;
},
getParamValue(obj, index, params) {
if (params.length < 1) {
return "";
return {};
}
let param = params[index];

View File

@ -145,8 +145,8 @@
<span>{{ scope.row.updateTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column
:label="$t('commons.operating')" min-width="150">
<el-table-column fixed="right"
:label="$t('commons.operating')" min-width="150">
<template v-slot:default="scope">
<ms-table-operator :is-tester-permission="true" @editClick="handleEdit(scope.row)"
@deleteClick="handleDelete(scope.row)">