前端获取接口数据下载Excel文档,文件流转换(封装方法)
封装方法,暴露出去
// 工具函数
/**
* @param {*} res 数据 二进制流
* @param {*} fileName 文件名
*/
export const exportFile = (res, fileName = 'fileData', fileType = 'xlsx') => {
if (!res) return
let url = ''
let blobTypeParams = {}
if (fileType === 'xls') {
blobTypeParams = {
type: 'application/vnd.ms-excel'
}
}
if (fileType === 'pdf') {
blobTypeParams = {
type: 'application/pdf'
}
}
if (fileType === 'xlsx') {
blobTypeParams = {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
}
}
if (fileType === 'zip') {
blobTypePar