/**
* @description[exportFile 导出文件]
* @author zoumiao
* @param {Object} data [blob数据]
* @param {String} title [文件名称]
* @returns {null} [没有返回]
*/
export const exportFile = function (data, title) {
let type = data.type
const relType = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
if (type.includes('application/json')) {
let reader = new FileReader()
reader.onload = function (event) {
let content = reader.result
let message = JSON.parse(content).message // 错误信息
// TODO 错误处理
}
reader.readAsText(data)
return true
}
if (relType.includes(type)) {
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', title)
document.body.appendChild(link)
link.click()
return true
}
// TODO 其他数据异常处理
}