前端傳的 參數(shù)太多get請求拼接參數(shù)無法滿足時 就需要改成post 直接下載文件
本文采用fetch請求服務(wù)端數(shù)據(jù),其他請求工具請自行修改
//這是我在廈門不動產(chǎn)登記系統(tǒng)寫的導(dǎo)出
exportExcelPost() {
const {mainList=[]} = this.props;
if(mainList.length==0){
Modal.warning({title:'提示',content:'當(dāng)前頁面沒有數(shù)據(jù)無法導(dǎo)出'});
return ;
}
this.setState({loading:true});
let body={mainList};
let params={
responseType:'blob', method: 'POST',mode : 'cors',credentials:'include',
};
body=JSON.stringify(body);
let headers = Object.assign({}, {
'Content-Type': 'application/json'
},);
fetch(callFeeDetailByTransactionExcel_export_excel, {body,headers,...params}).
then(res => {
if(res.status==200){
res.blob().then(blob=>{
const url=window.URL.createObjectURL(blob);
const filename="欠費案件清單.xlsx";
let a=document.getElementById("a_id");
a.href=url;
a.download=filename;
a.click();
window.URL.revokeObjectURL(url);
});
}
}
).finally(()=>{
this.setState({loading:false})
})
}
//這是我在 antd-pro 房產(chǎn)評估項目 里面寫的數(shù)據(jù)導(dǎo)出
onClick={async () => {
props.dispatch({ type: 'global/loading', loading: true });
const blob = await exportYbd({ ybdIdList:rowKeys });
props.dispatch({ type: 'global/loading', loading: false });
const url=window.URL.createObjectURL(blob);
const filename="住宅標(biāo)準樣本點數(shù)據(jù)庫樣本.xls";
const a=document.getElementById("a_id");
a.href=url;
a.download=filename;
a.click();
window.URL.revokeObjectURL(url);
}}