文件下载
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) {
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']);
a.href = e.target.result;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
callback();
return;
}
}
localStorage.setItem('pdfCtt', e.target.result);
window.open(`${window.location.origin}/institute_gjzy/pdf?id=${id}`, '_blank');
callback();
}
};
}
});
};