mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-14 08:28:40 +00:00
add download
This commit is contained in:
parent
e216330429
commit
487bd4a41b
|
|
@ -342,6 +342,29 @@ export class Form
|
||||||
{
|
{
|
||||||
console.log(xhr.response);
|
console.log(xhr.response);
|
||||||
|
|
||||||
|
if (xhr.getResponseHeader('content-type') === 'application/octet-stream') {
|
||||||
|
const blob = new Blob([xhr.response], { type: 'application/octet-stream' });
|
||||||
|
const doc = document.createElement('a');
|
||||||
|
doc.style = 'display: none';
|
||||||
|
document.body.appendChild(doc);
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
doc.href = url;
|
||||||
|
|
||||||
|
const disposition = xhr.getResponseHeader('content-disposition');
|
||||||
|
let filename = '';
|
||||||
|
if (disposition && disposition.indexOf('attachment') !== -1) {
|
||||||
|
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
||||||
|
const matches = filenameRegex.exec(disposition);
|
||||||
|
if (matches !== null && matches[1]) {
|
||||||
|
filename = matches[1].replace(/['"]/g, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.download = filename;
|
||||||
|
doc.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(doc);
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
const o = JSON.parse(xhr.response)[0],
|
const o = JSON.parse(xhr.response)[0],
|
||||||
response = new Response(o);
|
response = new Response(o);
|
||||||
|
|
@ -365,6 +388,7 @@ export class Form
|
||||||
+ 'Response: ' + xhr.response
|
+ 'Response: ' + xhr.response
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request.setResultCallback(0, function (xhr)
|
request.setResultCallback(0, function (xhr)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user