From 126c7ce5d2528c68f64695ea1decad15df47124d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Sat, 4 Mar 2023 05:46:01 +0000 Subject: [PATCH] =?UTF-8?q?!132=20fix:=20=E5=8A=A8=E6=80=81=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=B8=AD=EF=BC=8Cbody=E7=9A=84json=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BD=BF=E7=94=A8javasctipt=20Merge=20pull=20request=20!132=20?= =?UTF-8?q?from=20guo=5Fddt/master-fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/http.ts | 4 +++- src/utils/utils.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api/http.ts b/src/api/http.ts index a122d603..33950baa 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -172,7 +172,9 @@ export const customizeHttp = (targetParams: RequestConfigType, globalParams: Req case RequestBodyEnum.JSON: headers['Content-Type'] = ContentTypeEnum.JSON - data = translateStr(JSON.parse(targetRequestParams.Body['json'])) + //json对象也能使用'javasctipt:'来动态拼接参数 + data = translateStr(targetRequestParams.Body['json']) + if(typeof data === 'string') data = JSON.parse(data) // json 赋值给 data break diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 95203154..31f23b06 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -298,6 +298,10 @@ export const JSONStringify = (data: T) => { export const JSONParse = (data: string) => { return JSON.parse(data, (k, v) => { if (excludeParseEventKeyList.includes(k)) return v + if(typeof v === 'string' && v.indexOf('javascript:') > -1){ + //动态请求json中'javascript:'内容会影响模板content解析,直接返回 + return v + } if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) { return eval(`(function(){return ${v}})()`) } else if (typeof v === 'string' && v.indexOf && (v.indexOf('return ') > -1)) {