1、下载
console.log('流的方式下载文件',data);
let typeName = "";
typeName = this.cardExportParams.fileName;
let name = data.headers["content-disposition"];
if (name.indexOf(".xls") > -1) {
if (name.indexOf(".xlsx") > -1) {
name = typeName + ".xlsx";
} else {
name = typeName + ".xls";
}
} else if (name.indexOf(".zip") > -1) {
name = typeName + ".zip";
}
let blob = new Blob([data.data], {
// type: fileType //可去
});
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, name);
} else {
const a = window.document.createElement("a");
a.href = window.URL.createObjectURL(blob, {
type: "text/plain",
});
a.download = name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
},
2、导出信息
let that = this;
this.ajaxReset({
method: this.cardExportParams.method,
url: this.params.url,
isENoTip: true,
responseType: "blob",
isParseHtml: true,
isSNoTip: true,
timeout: 60 * 60 * 1000,
dealBlob: true,
mHeader: this.params.header || null,
mCode: this.params.code || null,
onSuccess(res) {
console.log('onSuccess',res)
// that.confirmLoading = false;
// resolve(res.data.data);
},
onError(res) {
console.log('onError',res);
// that.confirmLoading = false;
if (res.data && res.data.type === "application/json" || !res.data) {
if (res.data) {
res.data.text().then(data => {
that.$message.error(JSON.parse(data).errMsg);
// data:指成功读取到的内容
}).catch(err => {
//err: 指读取失败后返回的错误内容
that.$message.error("导出失败");
})
} else {
that.$message.error("导出失败");
}
} else {
that.download(res);
}
},
});
}


3、使用
fileName: `${this.channelName}授权`,
url,
method: 'get',
code: `导出${this.channelName}授权表`,
};
this.exportEpInfo();