var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { jsx as _jsx } from "react/jsx-runtime"; import React, { useState } from "react"; import { Button } from "antd"; import DownloadOutlined from "@ant-design/icons/DownloadOutlined"; import download from "downloadjs"; import axios from "axios"; import { getToken } from "@component/utils"; export const DownloadFile = (props) => { const { exportText = "导出", styleCss = { float: "right", height: "30px", lineHeight: "30px" }, params, icon } = props; const [loading, setLoading] = useState(false); function onExportFile() { return __awaiter(this, void 0, void 0, function* () { const { url, fileName } = params; setLoading(true); yield axios.get(url, { responseType: "blob", headers: { token: getToken() } }).then((response) => { return response.data; }).then((blob) => { setLoading(false); download(blob, fileName, "application/pdf"); }).catch(e => { console.log(e); }); }); } return (_jsx("div", Object.assign({ style: styleCss }, { children: _jsx(Button, Object.assign({ type: "link", onClick: onExportFile, loading: loading, icon: icon || _jsx(DownloadOutlined, {}) }, { children: exportText })) }))); };