mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
!132 fix: 动态请求中,body的json参数使用javasctipt
Merge pull request !132 from guo_ddt/master-fetch
This commit is contained in:
parent
800a0141a5
commit
126c7ce5d2
@ -172,7 +172,9 @@ export const customizeHttp = (targetParams: RequestConfigType, globalParams: Req
|
|||||||
|
|
||||||
case RequestBodyEnum.JSON:
|
case RequestBodyEnum.JSON:
|
||||||
headers['Content-Type'] = ContentTypeEnum.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
|
// json 赋值给 data
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -298,6 +298,10 @@ export const JSONStringify = <T>(data: T) => {
|
|||||||
export const JSONParse = (data: string) => {
|
export const JSONParse = (data: string) => {
|
||||||
return JSON.parse(data, (k, v) => {
|
return JSON.parse(data, (k, v) => {
|
||||||
if (excludeParseEventKeyList.includes(k)) return 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)) {
|
if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) {
|
||||||
return eval(`(function(){return ${v}})()`)
|
return eval(`(function(){return ${v}})()`)
|
||||||
} else if (typeof v === 'string' && v.indexOf && (v.indexOf('return ') > -1)) {
|
} else if (typeof v === 'string' && v.indexOf && (v.indexOf('return ') > -1)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user