fix (接口定义): 操作历史显示问题修复

--bug=1007196 --user=赵勇 【接口定义】-变更历史详情显示优化 https://www.tapd.cn/55049933/s/1056520
This commit is contained in:
fit2-zhao 2021-10-19 10:33:52 +08:00 committed by fit2-zhao
parent fe1dc1d9d6
commit 08969f31b4
2 changed files with 28 additions and 34 deletions

View File

@ -176,11 +176,15 @@ public class JsonDiff {
if (instruction.oper == Oper.INSERT || instruction.oper == Oper.DELETE) { if (instruction.oper == Oper.INSERT || instruction.oper == Oper.DELETE) {
applyPartial(origEl, instruction, value); applyPartial(origEl, instruction, value);
} else if (instruction.isIndexed()) { } else if (instruction.isIndexed()) {
if (!origEl.isJsonArray()) {
throw new IllegalArgumentException();
}
if (value.isJsonPrimitive()) { if (value.isJsonPrimitive()) {
((JzonArray) origEl).set(instruction.index, value); ((JzonArray) origEl).set(instruction.index, value);
} else if (origEl.isJsonObject()) {
if (value.isJsonPrimitive() || value.isJsonNull()) {
((JzonObject) origEl).add(key, value);
} else {
JzonElement childEl = ((JzonObject) origEl).get(key);
apply(childEl, value);
}
} else { } else {
if (((JzonArray) origEl).size() <= instruction.index) { if (((JzonArray) origEl).size() <= instruction.index) {
throw new IllegalArgumentException("Wrong index " + instruction.index + " for " + origEl); throw new IllegalArgumentException("Wrong index " + instruction.index + " for " + origEl);

View File

@ -22,9 +22,9 @@
<!--请求体--> <!--请求体-->
<el-tab-pane :label="$t('api_test.request.body')" name="body" v-if="request.body && (request.body.jsonSchema ||request.body.raw_1 || request.body.raw_2 )"> <el-tab-pane :label="$t('api_test.request.body')" name="body" v-if="request.body && (request.body.jsonSchema ||request.body.raw_1 || request.body.raw_2 )">
<el-radio-group v-model="activeBody" size="mini"> <el-radio-group v-model="activeBody" size="mini">
<el-radio-button label="json"/> <el-radio-button label="json" v-if="request.body.jsonSchema"/>
<el-radio-button label="raw"/> <el-radio-button label="raw" v-if="request.body.raw_1 || request.body.raw_2"/>
<el-radio-button label="form"/> <el-radio-button label="form" v-if="request.body.form"/>
</el-radio-group> </el-radio-group>
<ms-json-code-edit :body="request.body" ref="jsonCodeEdit" v-if="activeBody === 'json'"/> <ms-json-code-edit :body="request.body" ref="jsonCodeEdit" v-if="activeBody === 'json'"/>
<pre v-html="getDiff(request.body.raw_2,request.body.raw_1)" v-if="activeBody === 'raw'"></pre> <pre v-html="getDiff(request.body.raw_2,request.body.raw_1)" v-if="activeBody === 'raw'"></pre>
@ -99,34 +99,15 @@ export default {
} }
}, },
created() { created() {
if (this.request.header) { this.active();
this.activeName = "headers";
} else if (this.request.query) {
this.activeName = "parameters";
} else if (this.request.rest) {
this.activeName = "rest";
} else if (this.request.body && (this.request.body.jsonSchema || this.request.body.form || this.request.body.raw_1 || this.request.body.raw_2)) {
this.activeName = "body";
if (this.request.body.jsonSchema) {
this.activeBody = "json";
}
if (this.request.body.form) {
this.activeBody = "form";
}
if (this.request.body.raw_1 || this.request.body.raw_2) {
this.activeBody = "raw";
}
} else if (this.request.body_config) {
this.activeName = "advancedConfig";
} else if (this.request.body_auth) {
this.activeName = "authConfig";
} else if (this.request.statusCode) {
this.activeName = "statusCode";
}
this.reloadCodeEdit();
}, },
watch: { watch: {
'request.headerId'() { 'request.headerId'() {
this.active();
}
},
methods: {
active() {
if (this.request.header) { if (this.request.header) {
this.activeName = "headers"; this.activeName = "headers";
} else if (this.request.query) { } else if (this.request.query) {
@ -151,10 +132,19 @@ export default {
} else if (this.request.statusCode) { } else if (this.request.statusCode) {
this.activeName = "statusCode"; this.activeName = "statusCode";
} }
if (this.request.body && (this.request.body.jsonSchema || this.request.body.form || this.request.body.raw_1 || this.request.body.raw_2)) {
if (this.request.body.jsonSchema) {
this.activeBody = "json";
}
if (this.request.body.form) {
this.activeBody = "form";
}
if (this.request.body.raw_1 || this.request.body.raw_2) {
this.activeBody = "raw";
}
}
this.reloadCodeEdit(); this.reloadCodeEdit();
} },
},
methods: {
getDiff(v1, v2) { getDiff(v1, v2) {
let delta = jsondiffpatch.diff(v1, v2); let delta = jsondiffpatch.diff(v1, v2);
return formattersHtml.format(delta, v1); return formattersHtml.format(delta, v1);