From 70adf8a35352d9a0e9f89193567f26885601a86c Mon Sep 17 00:00:00 2001 From: "liu.shiyi" Date: Wed, 26 Jul 2023 10:21:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=88=90=E5=8A=9F=E7=BB=99=E5=87=BA=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataSetManagement/src/HttpEditForm.vue | 1 + .../packages/js/utils/httpParamsFormatting.js | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue b/data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue index 6a402d6d..60a8dffc 100644 --- a/data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue +++ b/data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue @@ -917,6 +917,7 @@ export default { } else { // 如果是后端代理,则将配置传到后端 const script = JSON.stringify(this.dataForm.config) + console.log(this.dataForm.config) const executeParams = { script, params: this.dataForm.paramsList, diff --git a/data-room-ui/packages/js/utils/httpParamsFormatting.js b/data-room-ui/packages/js/utils/httpParamsFormatting.js index 1fe11579..3bedf976 100644 --- a/data-room-ui/packages/js/utils/httpParamsFormatting.js +++ b/data-room-ui/packages/js/utils/httpParamsFormatting.js @@ -1,12 +1,13 @@ import axios from 'axios' import { Loading, Message } from 'element-ui' export default function axiosFormatting (customConfig) { + //将请求头和请求参数的值转化为对象形式 + const headers = arrToObject(customConfig.headers) + const params = arrToObject(customConfig.params) const httpConfig = { timeout: 1000 * 30, baseURL: '', - headers: { - ...customConfig.headers - } + headers } // let loadingInstance = null // 加载全局的loading const instance = axios.create(httpConfig) @@ -30,6 +31,10 @@ export default function axiosFormatting (customConfig) { // 执行响应脚本 const data = response.data.data eval(customConfig.responseScript) + Message({ + message: '执行成功', + type: 'success' + }) return Promise.resolve(data) } else { Message({ @@ -43,7 +48,7 @@ export default function axiosFormatting (customConfig) { instance({ method: customConfig.method, url: customConfig.url, - params: customConfig.params, + params, data: customConfig.method === 'post' ? customConfig.body : undefined }).then(response => { resolve(response) @@ -52,3 +57,11 @@ export default function axiosFormatting (customConfig) { }) }) } +// 数组转化为对象 +function arrToObject(list) { + const obj = {} + list.forEach(item=>{ + obj[item.key] = item.value + }) + return obj +}