fix: tinymce 图片上传结果解析不正确 (#2540)

* fix: tinymce 图片上传结果解析不正确

* 补充图片上传的文档说明
This commit is contained in:
吴多益 2021-09-13 10:32:33 +08:00 committed by GitHub
parent cf0ed6b461
commit e0a7ee2faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 8 deletions

View File

@ -26,7 +26,44 @@ order: 47
}
```
### tinymce 自定义配置
## 图片上传
通过设置 `receiver` 来支持文件上传,它的返回值类似如下:
```json
{
"link": "https://xxx.png"
}
```
也可以是
```json
{
"status": 0,
"data": {
"link": "https://xxx.png"
}
}
```
下面是个示例,但不会真正上传,每次都返回同一张图片
```schema: scope="body"
{
"type": "form",
"body": [
{
"type": "input-rich-text",
"receiver": "/api/mock2/sample/mirror?json={%22value%22:%22/amis/static/logo_c812f54.png%22}",
"name": "rich",
"label": "Rich Text"
}
]
}
```
## tinymce 自定义配置
可以设置 options 属性来自定义编辑器的展现,详细配置项请参考[官方文档](https://www.tiny.cloud/docs/general-configuration-guide/basic-setup/)。

View File

@ -187,7 +187,6 @@ export default class RichTextControl extends React.Component<
const fetcher = props.env.fetcher;
this.config = {
...props.options,
images_upload_url: props.receiver,
images_upload_handler: async (
blobInfo: any,
ok: (locaiton: string) => void,
@ -203,18 +202,24 @@ export default class RichTextControl extends React.Component<
data: payload
};
},
...normalizeApi(props.receiver)
...normalizeApi(props.receiver, 'post')
};
const response = await fetcher(receiver, formData, {
method: 'post'
});
if (response.ok) {
ok(
const location =
response.data?.link ||
response.data?.url ||
response.data?.value ||
(response as any).link
);
response.data?.url ||
response.data?.value ||
response.data?.data?.link ||
response.data?.data?.url ||
response.data?.data?.value;
if (location) {
ok(location);
} else {
console.warn('must have return value');
}
}
} catch (e) {
fail(e);