antd pro 实现文件下载
发布网友
发布时间:2022-11-28 00:54
我来回答
共1个回答
热心网友
时间:2023-10-19 20:20
这是POST 请求的:
export async function downloadDiagnosticLog(params) {
return request(`/api/v1/diagnosisLogController/download?${stringify(params, { arrayFormat: 'repeat' })}`);
}
* sendDownloadDiagnosticLog({ payload }, { call, put }) {
console.log('payload: ', payload);
const response= yield call(downloadDiagnosticLog, payload);
console.log('payload: ', response);
yield put({
type: 'respDownloadDiagnosticLog',
payload: response,
});
},
respDownloadDiagnosticLog(state, { payload }) {
return {
...state,
downloadDiagnosticLogState: payload,
};
},
async sendDownloadDiagnosticLog(id) {
const fileName= 'rowData.activeDepotName';//说白了就是给文件个名字
console.log(this);
await this.props.dispatch({//发送请求
type: 'DiagnosticLog/sendDownloadDiagnosticLog',
payload: { id: id ? [id] : this.state.selectedRowKeys},//参数
});
const { DiagnosticLog: { downloadDiagnosticLogState} } = this.props;
console.log(downloadDiagnosticLogState);
let response= downloadDiagnosticLogState;
const blob= new Blob([response]);//创建blob对象
const aLink= document.createElement('a');//创建a链接
aLink.style.display= 'none';
aLink.href= blob;
aLink.download= fileName;
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
};
<a href={`/api/v1/diagnosisLogController/download?id=${record.id}`}