import { MyResponseType } from '@/common'; import { ImportOutlined, InboxOutlined } from '@ant-design/icons'; import { Button, Flex, Modal, Upload, message } from 'antd'; import { useState } from 'react'; type MyImportModalType = { title?: string; type?: any; params?: Record; templateApi?: () => Promise; importApi: (data: any) => Promise; reload?: () => void; }; export function MyImportModal(props: MyImportModalType) { const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState(undefined); const { title = '批量导入', params = {}, type = 'primary' } = props; return ( <> {type === 'danger' ? ( ) : ( )} setOpen(false)} onOk={() => { if (!formData) return; setLoading(true); props ?.importApi(formData) .then(() => { message.success('导入操作成功'); setLoading(false); setOpen(false); props.reload?.(); return true; }) .catch(() => { setLoading(false); }); }} confirmLoading={loading} destroyOnClose={true} maskClosable={false} footer={(dom) => { return (
{dom}
); }} > { const isExcelFile = file.type === 'application/vnd.ms-excel' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; const isCSVFile = file.type === 'text/csv'; if (!isExcelFile && !isCSVFile) { message.error(`${file.name} is not an Excel or CSV file`); return Upload.LIST_IGNORE; } return true; }} customRequest={({ file }) => { const formData = new FormData(); formData.append('upload_file', file); Object.entries(params).forEach(([key, value]) => { formData.append(key, value); }); setFormData(formData); console.log('formData', formData, file); }} >

单击或拖动文件到此区域进行上传

支持单次上传。严禁上传公司数据或其他被禁止的文件。

); }