From 892065003d2c43b8d32c152aa0da2b9518e1fb2f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 29 Jul 2021 10:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=87=BA=E5=90=ABpa?= =?UTF-8?q?rams=E5=B1=9E=E6=80=A7=E5=AF=B9=E8=B1=A1=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/utils/request.js | 17 +---------------- ruoyi-ui/src/utils/ruoyi.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js index 46a593b6d..7e2e3495e 100644 --- a/ruoyi-ui/src/utils/request.js +++ b/ruoyi-ui/src/utils/request.js @@ -23,22 +23,7 @@ service.interceptors.request.use(config => { } // get请求映射params参数 if (config.method === 'get' && config.params) { - let url = config.url + '?'; - for (const propName of Object.keys(config.params)) { - const value = config.params[propName]; - var part = encodeURIComponent(propName) + "="; - if (value !== null && typeof(value) !== "undefined") { - if (typeof value === 'object') { - for (const key of Object.keys(value)) { - let params = propName + '[' + key + ']'; - var subPart = encodeURIComponent(params) + "="; - url += subPart + encodeURIComponent(value[key]) + "&"; - } - } else { - url += part + encodeURIComponent(value) + "&"; - } - } - } + let url = config.url + '?' + tansParams(config.params); url = url.slice(0, -1); config.params = {}; config.url = url; diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index 22e1ebf48..f60701e78 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -179,11 +179,21 @@ export function handleTree(data, id, parentId, children) { * @param {*} params 参数 */ export function tansParams(params) { - let result = '' - Object.keys(params).forEach((key) => { - if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) { - result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&' + let result = '' + for (const propName of Object.keys(params)) { + const value = params[propName]; + var part = encodeURIComponent(propName) + "="; + if (value !== null && typeof(value) !== "undefined") { + if (typeof value === 'object') { + for (const key of Object.keys(value)) { + let params = propName + '[' + key + ']'; + var subPart = encodeURIComponent(params) + "="; + result += subPart + encodeURIComponent(value[key]) + "&"; + } + } else { + result += part + encodeURIComponent(value) + "&"; + } } - }) + } return result }