Skip to content

Commit cbd6db2

Browse files
committed
feat(ExportImage): enhance image export functionality by integrating download service, adding support for multiple formats (PNG, JPEG, SVG, JSON, YAML), and improving user feedback during export process.
1 parent f6cff89 commit cbd6db2

1 file changed

Lines changed: 46 additions & 8 deletions

File tree

src/views/integrated/Workflow/tools/ExportImage.tsx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,75 @@
11
import { FileImageOutlined } from '@ant-design/icons';
2+
import { FlowDownloadFormat, FlowDownloadService } from '@flowgram.ai/export-plugin';
3+
import { usePlayground, useService } from '@flowgram.ai/free-layout-editor';
24
import type { MenuProps } from 'antd';
3-
import { Button, Dropdown, Tooltip } from 'antd';
5+
import { App, Button, Dropdown, Tooltip } from 'antd';
6+
import { useEffect, useState } from 'react';
47

58
/**
69
* 导出图片组件
710
* @returns
811
*/
912
const ExportImage: React.FC = () => {
13+
const { message } = App.useApp();
14+
// 正在导出中
15+
const [isExporting, setIsExporting] = useState(false);
16+
const playground = usePlayground();
17+
const { readonly } = playground.config;
18+
const downloadService = useService(FlowDownloadService);
19+
20+
// 监听导出进度
21+
useEffect(() => {
22+
const subscription = downloadService.onDownloadingChange((v) => {
23+
setIsExporting(v);
24+
});
25+
return () => subscription.dispose();
26+
}, [downloadService, readonly]);
27+
28+
// 处理下载导出
29+
const handleDownload = async (format: FlowDownloadFormat) => {
30+
await downloadService.download({ format });
31+
const formatOption = exportImageMenuItems?.find((option) => option?.key === format);
32+
if (formatOption) {
33+
message.success(`导出${formatOption.key}成功`);
34+
}
35+
};
36+
1037
// 导出图片菜单项
1138
const exportImageMenuItems: MenuProps['items'] = [
1239
{
13-
key: 'current-view-png',
40+
key: 'png',
1441
label: '导出为 PNG',
15-
onClick: () => console.log('导出当前视图为 PNG'),
42+
onClick: () => handleDownload(FlowDownloadFormat.PNG),
1643
},
1744
{
18-
key: 'current-view-jpeg',
45+
key: 'jpeg',
1946
label: '导出为 JPEG',
20-
onClick: () => console.log('导出当前视图为 JPEG'),
47+
onClick: () => handleDownload(FlowDownloadFormat.JPEG),
2148
},
2249
{
23-
key: 'current-view-svg',
50+
key: 'svg',
2451
label: '导出为 SVG',
25-
onClick: () => console.log('导出当前视图为 SVG'),
52+
onClick: () => handleDownload(FlowDownloadFormat.SVG),
53+
},
54+
{
55+
key: 'json',
56+
label: '导出为 JSON',
57+
onClick: () => handleDownload(FlowDownloadFormat.JSON),
58+
},
59+
{
60+
key: 'yaml',
61+
label: '导出为 YAML',
62+
onClick: () => handleDownload(FlowDownloadFormat.YAML),
2663
},
2764
];
2865

2966
return (
30-
<Tooltip title="导出图片" color="white">
67+
<Tooltip title="导出" color="white">
3168
<Dropdown
3269
menu={{
3370
items: exportImageMenuItems,
3471
}}
72+
disabled={isExporting}
3573
trigger={['click']}
3674
placement="bottomRight"
3775
>

0 commit comments

Comments
 (0)