feat: log 组件的接口支持配置 headers、data、method Closes #3283 (#3388)

This commit is contained in:
吴多益 2022-01-12 16:43:40 +08:00 committed by GitHub
parent c5ab2d3e94
commit a64d98a908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -117,6 +117,30 @@ public class StreamingResponseBodyController {
}
```
## source 支持高级配置
> 1.6.1 及以上版本
可以类似 api 那样自定义 header、method 等,比如:
```json
{
"type": "log",
"height": 300,
"source": {
"method": "post",
"url": "[/api/mock2/form/saveForm](http://localhost:3000/)",
"data": {
"myName": "${name}",
"myEmail": "${email}"
},
"headers": {
"my-header": "${myHeader}"
}
}
}
```
## 属性表
| 属性名 | 类型 | 默认值 | 说明 |
@ -126,3 +150,4 @@ public class StreamingResponseBodyController {
| autoScroll | `boolean` | true | 是否自动滚动 |
| placeholder | `string` | | 加载中的文字 |
| encoding | `string` | utf-8 | 返回内容的字符编码 |
| source | `string` | | 接口 |

View File

@ -131,7 +131,11 @@ export class Log extends React.Component<LogProps, LogState> {
if (!api.url) {
return;
}
const res = await fetch(api.url);
const res = await fetch(api.url, {
method: api.method?.toLocaleUpperCase() || 'GET',
headers: (api.headers as Record<string, string>) || undefined,
body: api.data ? JSON.stringify(api.data) : undefined
});
if (res.status === 200) {
const body = res.body;
if (!body) {