|
@@ -57,13 +57,14 @@ export function download(option) {
|
|
|
data: "",
|
|
|
fileName: "",
|
|
|
header: "",
|
|
|
+ responseType: "",
|
|
|
};
|
|
|
let opt = objAssign(defOpt, option);
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
xhr.open(opt.type.toUpperCase(), opt.url, true);
|
|
|
- xhr.responseType = "blob";
|
|
|
+ if (opt.responseType) xhr.responseType = opt.responseType;
|
|
|
|
|
|
// header set
|
|
|
if (opt.header && objTypeOf(opt.header) === "object") {
|
|
@@ -74,26 +75,7 @@ export function download(option) {
|
|
|
|
|
|
xhr.onload = function () {
|
|
|
if (this.readyState === 4 && this.status === 200) {
|
|
|
- if (this.response.size < 1024) {
|
|
|
- reject("文件不存在!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var blob = this.response;
|
|
|
- let pdfUrl = "";
|
|
|
- let uRl = window.URL || window.webkitURL;
|
|
|
- if (uRl && uRl.createObjectURL) {
|
|
|
- pdfUrl = uRl.createObjectURL(blob);
|
|
|
- } else {
|
|
|
- reject("浏览器不兼容!");
|
|
|
- }
|
|
|
- let a = document.createElement("a");
|
|
|
- a.download = opt.fileName;
|
|
|
- a.href = pdfUrl;
|
|
|
- document.body.appendChild(a);
|
|
|
- a.click();
|
|
|
- a.parentNode.removeChild(a);
|
|
|
- resolve(true);
|
|
|
+ resolve(this.response);
|
|
|
} else {
|
|
|
reject("请求错误!");
|
|
|
}
|