You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
32 lines
1.2 KiB
import { jsx as _jsx } from "react/jsx-runtime"; |
|
import React from 'react'; |
|
import { Button, message } from 'antd'; |
|
import { useRequest, useToggle } from 'ahooks'; |
|
import DownloadOutlined from '@ant-design/icons/DownloadOutlined'; |
|
import download from 'downloadjs'; |
|
export const ExportFile = (props) => { |
|
const { exportText = '导出', styleCss = { |
|
float: 'right', |
|
height: '30px', |
|
lineHeight: '30px', |
|
}, service, params, icon, type, fileName = Date.now(), } = props; |
|
const { run, loading } = useRequest(service, { |
|
manual: true, |
|
throttleWait: 10000, |
|
onSuccess(res) { |
|
if (res.message && res.success != true) { |
|
message.warning(res.message); |
|
} |
|
else { |
|
download(res, `${fileName}.${type || 'csv'}`); |
|
} |
|
}, |
|
onError(res) { |
|
message.error(res.message); |
|
}, |
|
}); |
|
function onExportFile() { |
|
run(params); |
|
} |
|
return (_jsx("div", Object.assign({ style: styleCss }, { children: _jsx(Button, Object.assign({ type: "link", onClick: onExportFile, loading: loading, icon: icon || _jsx(DownloadOutlined, {}) }, { children: exportText })) }))); |
|
};
|
|
|