From 9ca4c37b0836a81f0f78d18a70ddc21b116114b3 Mon Sep 17 00:00:00 2001 From: Gszekt Date: Tue, 28 Jul 2020 21:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=89=8D=E7=AB=AF=E7=9A=84=E7=9A=84?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=AF=B9=E8=B1=A1=E5=80=BC=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E5=88=B0=E5=90=8E=E7=AB=AF=E5=AE=9E=E4=BE=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=20params=20=E5=8F=82=E6=95=B0=E3=80=82=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E5=86=99=E6=B3=95=E9=87=87=E7=94=A8=E6=9B=B4?= =?UTF-8?q?=E7=AC=A6=E5=90=88=E7=9B=B4=E8=A7=89=E7=9A=84=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=9A{=20=20=20=20=20name:=20'22',=20=20=20=20=20params:=20?= =?UTF-8?q?{=20=20=20=20=20=20=20=20=20age:=20'21',=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20weight:=2060=20=20=20=20=20}=20}=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E4=B9=9F=E6=94=AF=E6=8C=81=E6=99=AE=E9=80=9A=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C{=20=20=20=20=20name:=20'22',=20=20?= =?UTF-8?q?=20=20=20'params[age]':=20'21',=20=20=20=20=20'params[weight]':?= =?UTF-8?q?=2060=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/utils/request.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js index 5d1cfd36..215cee3f 100644 --- a/ruoyi-ui/src/utils/request.js +++ b/ruoyi-ui/src/utils/request.js @@ -20,6 +20,27 @@ service.interceptors.request.use(config => { if (getToken() && !isToken) { config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 } + + let url = config.url; + if (config.method === 'get' && config.params) { + url += '?'; + let keys = Object.keys(config.params); + for (const key of keys) { + const value = config.params[key]; + if (typeof value === 'object') { + for (const key2 of Object.keys(value)) { + let key3 = key + '[' + key2 + ']'; + url += `${encodeURIComponent(key3)}=${value[key2] == undefined ? '' : encodeURIComponent(value[key2])}&`; + } + } else { + url += `${encodeURIComponent(key)}=${config.params[key] == undefined ? '' : encodeURIComponent(config.params[key])}&`; + } + } + url = url.substring(0, url.length - 1); + config.params = {}; + } + config.url = url; + return config }, error => { console.log(error)