diff --git a/frontend/src/business/components/api/test/components/ApiKeyValue.vue b/frontend/src/business/components/api/test/components/ApiKeyValue.vue index 8e8de5f923..cf4840bcd7 100644 --- a/frontend/src/business/components/api/test/components/ApiKeyValue.vue +++ b/frontend/src/business/components/api/test/components/ApiKeyValue.vue @@ -39,48 +39,8 @@ :visible.sync="itemValueVisible" class="advanced-item-value" width="70%"> - - + - - - - - + +
+ + + + + +
+ +
+
+
+
-
@@ -119,11 +78,14 @@
- + {{ $t('commons.save') }} - + + {{ $t('api_test.request.parameters_advance_add_func') }} + + {{ $t('api_test.request.parameters_preview') }} @@ -246,28 +208,68 @@ export default { return (func.name.toLowerCase().indexOf(queryString.toLowerCase()) > -1); }; }, - showPreview(itemValue) { - this.itemValuePreview = calculate(itemValue); - }, - addFunc(func) { - this.itemFuncs.push(func); - }, - appendFunc(func) { - if (this.itemValue) { - this.itemValue += " | " + func; - } else { - this.$warning(this.$t("api_test.request.parameters_preview_warning")); + showPreview() { + // 找到变量本身 + if (!this.itemValue) { + return; } + let index = this.itemValue.indexOf("|"); + if (index > -1) { + this.itemValue = this.itemValue.substring(0, index).trim(); + } + + this.itemFuncs.forEach(f => { + if (!f.name) { + return; + } + this.itemValue += "|" + f.name; + if (f.params) { + this.itemValue += ":" + f.params.map(p => p.value).join(","); + } + }); + + this.itemValuePreview = calculate(this.itemValue); + }, + methodChange(itemFunc, func) { + let index = this.itemFuncs.indexOf(itemFunc); + this.itemFuncs = this.itemFuncs.slice(0, index); + // 这里要用 deep copy + this.itemFuncs.push(JSON.parse(JSON.stringify(func))); + this.showPreview(); + }, + addFunc() { + if (this.itemFuncs.length > 4) { + this.$info(this.$t('api_test.request.parameters_advance_add_func_limit')); + return; + } + if (this.itemFuncs.length > 0) { + let func = this.itemFuncs[this.itemFuncs.length - 1]; + if (!func.name) { + this.$warning(this.$t('api_test.request.parameters_advance_add_func_error')); + return; + } + if (func.params) { + for (let j = 0; j < func.params.length; j++) { + if (!func.params[j].value) { + this.$warning(this.$t('api_test.request.parameters_advance_add_param_error')); + return; + } + } + } + } + this.itemFuncs.push({name: '', params: []}); }, advanced(item) { this.currentItem = item; this.itemValueVisible = true; - this.itemValue = item.value; + this.itemValue = ''; this.itemValuePreview = null; + this.itemFuncs = []; }, saveAdvanced() { this.currentItem.value = this.itemValue; this.itemValueVisible = false; + this.itemFuncs = []; } }, created() { @@ -299,19 +301,8 @@ export default { padding: 15px 25px; } -.format-tip { - background: #EDEDED; -} - -.format-tip { - border: solid #E1E1E1 1px; - margin: 10px 0; - padding: 10px; - border-radius: 3px; -} - -.func-background { - background: #2395f1; +.el-row { + margin-bottom: 5px; } diff --git a/frontend/src/common/js/func-filter.js b/frontend/src/common/js/func-filter.js index 5d8dc48c28..c3fd151e64 100644 --- a/frontend/src/common/js/func-filter.js +++ b/frontend/src/common/js/func-filter.js @@ -73,7 +73,7 @@ export const funcFilters = { lconcat: function (str, ...args) { args.forEach(item => { - str = item + this._string; + str = item + str; }); return str; }, diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 2d07634630..5be929c03b 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -403,6 +403,11 @@ export default { parameters_advance: "Advanced parameter settings", parameters_preview: "Preview", parameters_preview_warning: "Please enter the template first", + parameters_advance_mock: "Mock Data", + parameters_advance_add_func: "Add Function", + parameters_advance_add_func_limit: "Support up to 5 functions", + parameters_advance_add_func_error: "Please select function first", + parameters_advance_add_param_error: "Please enter function parameters", parameters_desc: "Parameters will be appended to the URL e.g. https://fit2cloud.com?Name=Value&Name2=Value2", headers: "Headers", body: "Body", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index bf943918e5..072ba2b5dd 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -406,6 +406,11 @@ export default { parameters_advance: "高级参数设置", parameters_preview: "预览", parameters_preview_warning: "请先输入模版", + parameters_advance_mock: "Mock 数据", + parameters_advance_add_func: "添加函数", + parameters_advance_add_func_limit: "最多支持5个函数", + parameters_advance_add_func_error: "请先选择函数", + parameters_advance_add_param_error: "请输入函数参数", parameters_desc: "参数追加到URL,例如https://fit2cloud.com/entries?key1=Value1&Key2=Value2", headers: "请求头", body: "请求内容", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 1a0024912a..86a7e65b3f 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -403,6 +403,11 @@ export default { parameters_advance: "高級參數設置", parameters_preview: "預覽", parameters_preview_warning: "請先輸入模版", + parameters_advance_mock: "Mock 數據", + parameters_advance_add_func: "添加函數", + parameters_advance_add_func_limit: "最多支持5個函數", + parameters_advance_add_func_error: "請先選擇函數", + parameters_advance_add_param_error: "請輸入函數參數", parameters_desc: "參數追加到URL,例如https://fit2cloud.com/entries?key1=Value1&Key2=Value2", headers: "請求頭", body: "請求內容",