import { accessCenterSysLogDownload } from '@/services/accesscenter/accessCenter';
import { DownloadOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import moment from 'moment';
const DownLoadLogManagement: React.FC<{ queryBody: any }> = ({ queryBody }) => {
function download() {
const nowTime = moment().format('YYYY-MM-DD-HH-mm-ss');
accessCenterSysLogDownload({ request: queryBody['request'] }).then((res) => {
const blob = new Blob([res]);
const objectURL = URL.createObjectURL(blob);
const btn = document.createElement('a');
const body = document.querySelector('body');
if (body) {
body.appendChild(btn);
}
btn.download = `${nowTime}-log.xlsx`;
btn.href = objectURL;
btn.click();
if (body) {
body.removeChild(btn); // 删除标签
}
});
}
return (
<>
<Button key="show" onClick={download}>
导出 <DownloadOutlined />
</Button>
,
</>
);
};
export default DownLoadLogManagement;
// 日志下载
export async function accessCenterSysLogDownload(body: any, options?: any) {
return request<any>('/sysLog/download', {
method: 'POST',
data: body,
responseType: 'blob', // 需要指定文档流类型
...(options || {}),
});
}