Open dlrandy opened 5 years ago
export function onDownload(data, filename, mime) {
var blob = new Blob([data], {type: mime || 'application/octet-stream'});
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(blob, filename);
}
else {
var blobURL = window.URL.createObjectURL(blob);
var tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', filename);
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank');
}
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
}
}
export function onDownloadIframe(url) {
const iframe = document.createElement('iframe');
iframe.setAttribute('id', 'download_file_iframe');
const form = document.createElement('form');
form.setAttribute('method', 'get');
form.setAttribute('action', url);//can not carry the queru, or you can use restfule or post method
// form.setAttribute('target', '_blank');
iframe.appendChild(form);
document.body.appendChild(iframe);
form.submit();
document.body.removeChild(iframe);
}
reportInst.defaults.headers['Accept'] ='application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, /'; return reportInst.get('/users.xlsx', {//'/file/index.xlsx' responseType: 'blob', ...options }); }
export function onDownloadIframe(id) {
const url = '/cet3etwst/report/'+ id +'/users.xlsx';
const iframe = document.createElement('iframe');
iframe.setAttribute('id', 'download_file_iframe');
const form = document.createElement('form');
form.setAttribute('method', 'get');
form.setAttribute('action', url);
// form.setAttribute('target', '_blank');
iframe.appendChild(form);
document.body.appendChild(iframe);
form.submit();
document.body.removeChild(iframe);
}
function deleteCol(index, table) { var len = table.rows.length; for (var i = 0; i < len; i++) { table.rows[i].deleteCell(index); } } export const exportTableToExcel = (function() { const uri = "data:application/vnd.ms-excel;base64,", template = '
if (removeColumn) {
deleteCol(removeColumn, table);
}
var ctx = { worksheet: name || "Worksheet", table: table.innerHTML };
// window.location.href = uri + base64(format(template, ctx))
downloadLink.download = name;
downloadLink.href = uri + base64(format(template, ctx));
downloadLink.click();
}; })();