zksu
/
WEB
forked from yoone/WEB
1
0
Fork 0
WEB/src/pages/Dict/components/DictItemExportButton.tsx

54 lines
1.3 KiB
TypeScript

import { DownloadOutlined } from '@ant-design/icons';
import { Button, message } from 'antd';
import React from 'react';
// 字典项导出按钮组件的属性接口
interface DictItemExportButtonProps {
// 当前选中的字典
selectedDict?: any;
// 是否禁用按钮
disabled?: boolean;
// 自定义导出函数
onExport?: () => Promise<void>;
}
// 字典项导出按钮组件
const DictItemExportButton: React.FC<DictItemExportButtonProps> = ({
selectedDict,
disabled = false,
onExport,
}) => {
// 处理导出操作
const handleExport = async () => {
if (!selectedDict) {
message.warning('请先选择字典');
return;
}
try {
// 如果提供了自定义导出函数,则使用自定义函数
if (onExport) {
await onExport();
} else {
// 如果没有提供自定义导出函数,这里可以添加默认逻辑
message.warning('未提供导出函数');
}
} catch (error: any) {
message.error('导出字典项失败:' + (error.message || '未知错误'));
}
};
return (
<Button
size="small"
icon={<DownloadOutlined />}
onClick={handleExport}
disabled={disabled || !selectedDict}
>
</Button>
);
};
export default DictItemExportButton;