ant design 文件下载
生活随笔
收集整理的這篇文章主要介紹了
ant design 文件下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文件下載//導出報表
const exportExel = () => {axios({method: 'post',url: '/insMngGjzy/comb/attribution/export',responseType: 'arraybuffer',data: {combId: Number(id),type: tempOthers?.type || 4,startDate: tempOthers?.dateArr?.[0] || '',endDate: tempOthers?.dateArr?.[1] || '',industryCode: tempOthers?.industryCode || infoObj?.hydm || 0},headers: {clientType: 1,accessToken:getCookie('token') ||'DC0956D491D5BCA4B86809D38DD5C5CB2CA3350B6BE7D98DEEF4EBDDF721A92735FE7A58BA18AE7B6EBDACEEFE27DFF845D0158C216718F3'}}).then((res: any) => {getFile(res,`${infoObj.zzmc}-${infoObj.zhmc}業績歸因報表`,'xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');});};export const getFile = (res: any, title: string, suffix: string, type: string) => {const blob = new Blob([res.data], { type });const reader = new FileReader();reader.readAsDataURL(blob);reader.onload = e => {const a = document.createElement('a');a.download = `${title}.${suffix || 'xls'}`;a.href = e.target.result;document.body.appendChild(a);a.click();document.body.removeChild(a);};};//下載文件const getUrl = () => {dispatch({type: 'combManage/goGetSysUrl',payload: {type: 'STOCK_POOL_IMPORT_MODEL'},callback: (res: any) => {if (res.code === 1008) {downLoadFromUrl(res.data.url);}}});};export const downLoadFromUrl = (url: string) => {if (url) {var x = new XMLHttpRequest();x.open('GET', url, true);x.responseType = 'blob';x.onload = function(e) {download(x.response, url.substr(url.lastIndexOf('/') + 1), 'application/vnd.ms-excel');};x.send();}};//下載圖片const getQqrCode=()=>{axios({method: 'post',url: '/InvestmentAssistant/qrCode/image.do',responseType: 'arraybuffer',data: {type:1},headers: {clientType: 1,}}).then((res: any) => {var data = res.data;let imageUrl ="data:image/png;base64," +btoa(new Uint8Array(data).reduce((data, byte) => data + String.fromCharCode(byte),""));setCode(imageUrl)},()=>{setCode("")});}
// 獲取研報并且跳轉
export const getReport = (id: number | string,flag: string,reportTitle: string,callback: () => {}
) => {axios({method: 'get',url: `/insMngGjzy/report/${flag}/${id}`,responseType: 'arraybuffer',headers: {clientType: 1,accessToken:getCookie('token') ||'DC0956D491D5BCA4B86809D38DD5C5CB2CA3350B6BE7D98DEEF4EBDDF721A92735FE7A58BA18AE7B6EBDACEEFE27DFF845D0158C216718F3'}}).then((res: any) => {console.log('resres', res);if (res?.status === 200) {const blob = new Blob([res.data], { type: '' });const reader = new FileReader();reader.readAsDataURL(blob);reader.onload = e => {if (e.target.result) {//docx類型if (res.headers['content-disposition']) {if (res.headers['content-disposition'].indexOf('docx') > -1) {let disposition: { [key: string]: any } = { filename: reportTitle + '.docx' };const headersContent = res.headers['content-disposition'].split(';');headersContent.forEach((item: string) => {const itemArr = item.split('=');if (itemArr.length === 2) {disposition[itemArr[0].trim()] = itemArr[1];}});// 文件流const a = document.createElement('a');a.download = decodeURIComponent(disposition['filename']); //對中文進行解碼decodeURIComponent方法a.href = e.target.result;document.body.appendChild(a);a.click();document.body.removeChild(a);callback();return;}}//pdf類型localStorage.setItem('pdfCtt', e.target.result);window.open(`${window.location.origin}/institute_gjzy/pdf?id=${id}`, '_blank');callback();}};}});
};
總結
以上是生活随笔為你收集整理的ant design 文件下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rtx linux 显卡,linux R
- 下一篇: CRM实施能给客户带来什么好处