解决${}变量请求体格式化问题

This commit is contained in:
chenjianxing 2020-12-28 10:43:03 +08:00
parent 0d037a9165
commit 08b75e5ddb
4 changed files with 33 additions and 6 deletions

@ -1 +1 @@
Subproject commit f27d1609d77f7d6c988d37d709466e844d350e17 Subproject commit 79343a2763b014355f91fc21b2356a95ae437973

View File

@ -19,7 +19,7 @@
type="body" type="body"
v-if="body.isKV()"/> v-if="body.isKV()"/>
<div class="body-raw" v-if="body.type == 'Raw'"> <div class="body-raw" v-if="body.type == 'Raw'">
<ms-code-edit :mode="body.format" :enable-format="false" :read-only="isReadOnly" :data.sync="body.raw" :modes="modes" ref="codeEdit"/> <ms-code-edit v-if="isCodeEditAlive" :mode="body.format" :read-only="isReadOnly" :data.sync="body.raw" :modes="modes" ref="codeEdit"/>
</div> </div>
</div> </div>
@ -43,20 +43,26 @@ export default {
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
} },
}, },
data() { data() {
return { return {
type: BODY_TYPE, type: BODY_TYPE,
modes: ['text', 'json', 'xml', 'html'] modes: ['text', 'json', 'xml', 'html'],
isCodeEditAlive: true
}; };
}, },
methods: { methods: {
modeChange(mode) { modeChange(mode) {
this.body.format = mode; this.body.format = mode;
} this.reload();
},
reload() {
this.isCodeEditAlive = false;
this.$nextTick(() => (this.isCodeEditAlive = true));
},
}, },
created() { created() {

@ -1 +1 @@
Subproject commit 7d43154a7c19732407a8e9ace8a7d1ea13c91f36 Subproject commit 8cda5c873cd9985c97adb34efacf507167fa4182

View File

@ -6,10 +6,21 @@ export function formatJson (json) {
indentLevel = 0, indentLevel = 0,
inString = false, inString = false,
currentChar = null; currentChar = null;
let flag = false;
for (i = 0, il = json.length; i < il; i += 1) { for (i = 0, il = json.length; i < il; i += 1) {
currentChar = json.charAt(i); currentChar = json.charAt(i);
switch (currentChar) { switch (currentChar) {
case '{': case '{':
if (i != 0 && json.charAt(i - 1) === '$') {
newJson += currentChar;
flag = true;
} else if (!inString) {
newJson += currentChar + "\n" + repeat(tab, indentLevel + 1);
indentLevel += 1
} else {
newJson += currentChar
}
break;
case '[': case '[':
if (!inString) { if (!inString) {
newJson += currentChar + "\n" + repeat(tab, indentLevel + 1); newJson += currentChar + "\n" + repeat(tab, indentLevel + 1);
@ -19,6 +30,16 @@ export function formatJson (json) {
} }
break; break;
case '}': case '}':
if (flag) {
newJson += currentChar;
flag = false;
} else if (!inString) {
indentLevel -= 1;
newJson += "\n" + repeat(tab, indentLevel) + currentChar
} else {
newJson += currentChar
}
break;
case ']': case ']':
if (!inString) { if (!inString) {
indentLevel -= 1; indentLevel -= 1;