feat: input-rich-text 的图片上传支持自定义文件字段 Closes #3287 (#3387)

* feat: input-rich-text 的图片上传支持自定义字段

* 换成 fileField
This commit is contained in:
吴多益 2022-01-12 16:34:20 +08:00 committed by GitHub
parent 1f6ece5586
commit c5ab2d3e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -28,7 +28,11 @@ order: 47
## 图片上传
通过设置 `receiver` 来支持文件上传,它的返回值类似如下:
通过设置 `receiver` 来支持文件上传,如果是 tinymce它会将图片放在 `file` 字段中
> 1.6.1 及以上版本可以通过 fileField 字段修改
它的返回值类似如下:
```json
{
@ -55,7 +59,7 @@ order: 47
"body": [
{
"type": "input-rich-text",
"receiver": "/api/mock2/sample/mirror?json={%22value%22:%22/amis/static/logo_c812f54.png%22}",
"receiver": "/api/mock2/sample/mirror?json={%22link%22:%22/amis/static/logo_c812f54.png%22}",
"name": "rich",
"label": "Rich Text"
}
@ -146,6 +150,7 @@ froala 可以通过设置 buttons 参数来控制显示哪些按钮,默认是
| saveAsUbb | `boolean` | | 是否保存为 ubb 格式 |
| receiver | [API](../../../docs/types/api) | | 默认的图片保存 API |
| videoReceiver | [API](../../../docs/types/api) | | 默认的视频保存 API |
| fileField | string | | 上传文件时的字段名 |
| size | `string` | | 框的大小,可设置为 `md` 或者 `lg` |
| options | `object` | | 需要参考 [tinymce](https://www.tiny.cloud/docs/configure/integration-and-setup/) 或 [froala](https://www.froala.com/wysiwyg-editor/docs/options) 的文档 |
| buttons | `Array<string>` | | froala 专用配置显示的按钮tinymce 可以通过前面的 options 设置 [toolbar](https://www.tiny.cloud/docs/demo/custom-toolbar-button/) 字符串 |

View File

@ -18,6 +18,11 @@ export interface RichTextControlSchema extends FormBaseControl {
receiver?: string;
videoReceiver?: string;
/**
*
*/
fileField?: string;
/**
*
*/
@ -48,6 +53,7 @@ export default class RichTextControl extends React.Component<
imageEditable: true,
receiver: '/api/upload/image',
videoReceiver: '/api/upload/video',
fileField: 'file',
placeholder: 'placeholder.enter',
options: {
toolbarButtons: [
@ -141,7 +147,11 @@ export default class RichTextControl extends React.Component<
fail: (reason: string) => void
) => {
const formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append(
props.fileField,
blobInfo.blob(),
blobInfo.filename()
);
try {
const receiver = {
adaptor: (payload: object) => {