feat: 高级参数设置预览

This commit is contained in:
Captain.B 2020-08-07 17:37:29 +08:00
parent fdda9b00b0
commit 5bc5eeb4db
1 changed files with 28 additions and 17 deletions

View File

@ -47,8 +47,11 @@
</el-form> </el-form>
<div> <div>
<el-row type="flex" align="middle"> <el-row type="flex" align="middle">
<el-col :span="3"> <el-col :span="6">
<el-button class="save-button" type="success" plain @click="showPreview(itemValue)"> <el-button size="small" type="primary" plain @click="saveAdvanced()">
{{ $t('commons.save') }}
</el-button>
<el-button size="small" type="success" plain @click="showPreview(itemValue)">
{{ $t('api_test.request.parameters_preview') }} {{ $t('api_test.request.parameters_preview') }}
</el-button> </el-button>
</el-col> </el-col>
@ -171,24 +174,27 @@ export default {
if (!itemValue) { if (!itemValue) {
return; return;
} }
let funcs = itemValue.split("|"); try {
let value = Mock.mock(funcs[0].trim()); let funcs = itemValue.split("|");
if (funcs.length === 1) { let value = Mock.mock(funcs[0].trim());
if (funcs.length === 1) {
this.itemValuePreview = value;
return value;
}
for (let i = 1; i < funcs.length; i++) {
let func = funcs[i].trim();
let args = func.split(":");
let strings = [];
if (args[1]) {
strings = args[1].split(",");
}
value = funcFilters[args[0].trim()](value, ...strings);
}
this.itemValuePreview = value; this.itemValuePreview = value;
return value; return value;
} catch (e) {
this.itemValuePreview = itemValue;
} }
for (let i = 1; i < funcs.length; i++) {
let func = funcs[i].trim();
let args = func.split(":");
let strings = [];
if (args[1]) {
strings = args[1].split(",");
}
value = funcFilters[args[0].trim()](value, ...strings);
}
this.itemValuePreview = value;
return value;
}, },
appendFunc(func) { appendFunc(func) {
if (this.itemValue) { if (this.itemValue) {
@ -198,9 +204,14 @@ export default {
} }
}, },
advanced(item) { advanced(item) {
this.currentItem = item;
this.itemValueVisible = true; this.itemValueVisible = true;
this.itemValue = item.value; this.itemValue = item.value;
}, },
saveAdvanced() {
this.currentItem.value = this.itemValue;
this.itemValueVisible = false;
}
}, },
created() { created() {
if (this.items.length === 0) { if (this.items.length === 0) {