示例
const handleExport = async () => {
try {
const res = await evaluationApi.value.valuationExport(
{
parkIds: queryParams?.value?.parkIds,
searchValue: queryParams?.value?.searchValue,
generateStartTime: queryParams?.value?.generateStartTime,
generateEndTime: queryParams?.value?.generateEndTime,
evaluationType: queryParams?.value?.evaluationType,
evaluationStatuses: queryParams?.value?.evaluationStatuses,
},
{
responseType: 'blob',
}
);
const blob = new Blob([res.data!], { type: 'application/vnd.ms-excel' });
downloadBlob(`评价看板导出_${dayjs().format('YYYYMMDDHHmmss')}.xls`, blob);
} catch (error) {
message.error(`${error}`);
}
};
export function downloadBlob(filename: string, blob: Blob) {
if (isHworkQiankun) {
const fileURL = window.URL.createObjectURL(blob);
window.open(fileURL, 'download', filename);
} else if ((window as any).navigator!.msSaveBlob) {
(window as any).navigator!.msSaveBlob(blob, filename);
} else {
const fileURL = window.URL.createObjectURL(blob);
const aEl = document.createElement('a');
aEl.href = fileURL;
aEl.download = filename;
document.body.appendChild(aEl);
aEl.click();
document.body.removeChild(aEl);
window.URL.revokeObjectURL(fileURL);
}
}
网友评论