|
|
@ -330,33 +330,20 @@ export default { |
|
|
|
await this.$http({ |
|
|
|
method: 'POST', |
|
|
|
url, |
|
|
|
// responseType: 'blob', |
|
|
|
responseType: 'blob', |
|
|
|
data: params |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
console.log('res----dddd', res) |
|
|
|
// this.download(res.data, title + '.xls') |
|
|
|
// this.getTemplateList() |
|
|
|
|
|
|
|
this.exportLoading = false |
|
|
|
if (res.data.code && res.data.code == 9999) { |
|
|
|
return this.$message.error(res.data.msg) |
|
|
|
} |
|
|
|
if (res.headers["content-disposition"]) { |
|
|
|
let fileName = window.decodeURI(res.headers["content-disposition"].split(";")[1].split("=")[1]) |
|
|
|
console.log('filename', fileName) |
|
|
|
let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) |
|
|
|
var url = window.URL.createObjectURL(blob) |
|
|
|
var aLink = document.createElement('a') |
|
|
|
aLink.style.display = 'none' |
|
|
|
aLink.href = url |
|
|
|
aLink.setAttribute('download', fileName) |
|
|
|
document.body.appendChild(aLink) |
|
|
|
aLink.click() |
|
|
|
document.body.removeChild(aLink) //下载完成移除元素 |
|
|
|
window.URL.revokeObjectURL(url) //释放掉blob对象 |
|
|
|
this.$message.success('导出成功') |
|
|
|
this.$emit('close') |
|
|
|
} else this.$message.error('下载失败') |
|
|
|
// if (res.data.code && res.data.code == 9999) { |
|
|
|
// return this.$message.error(res.data.msg) |
|
|
|
// } |
|
|
|
this.formatData(res) |
|
|
|
|
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log('err', err) |
|
|
@ -431,6 +418,40 @@ export default { |
|
|
|
this.$message.error(msg) |
|
|
|
} |
|
|
|
}, |
|
|
|
formatData(res) { |
|
|
|
const fileReader = new FileReader() |
|
|
|
fileReader.onloadend = () => { |
|
|
|
try { |
|
|
|
const jsonData = JSON.parse(fileReader.result) // 说明是普通对象数据,后台转换失败 |
|
|
|
// 后台信息 |
|
|
|
console.log('jsonData---1', jsonData) |
|
|
|
return this.$message.error(jsonData.msg) |
|
|
|
} catch (err) { // 解析成对象失败,说明是正常的文件流 |
|
|
|
// 下载文件 |
|
|
|
console.log('errr-----', err, this) |
|
|
|
this.downloadFile(res) |
|
|
|
} |
|
|
|
} |
|
|
|
fileReader.readAsText(res.data) |
|
|
|
}, |
|
|
|
downloadFile(res) { |
|
|
|
if (res.headers["content-disposition"]) { |
|
|
|
let fileName = window.decodeURI(res.headers["content-disposition"].split(";")[1].split("=")[1]) |
|
|
|
console.log('filename', fileName) |
|
|
|
let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) |
|
|
|
var url = window.URL.createObjectURL(blob) |
|
|
|
var aLink = document.createElement('a') |
|
|
|
aLink.style.display = 'none' |
|
|
|
aLink.href = url |
|
|
|
aLink.setAttribute('download', fileName) |
|
|
|
document.body.appendChild(aLink) |
|
|
|
aLink.click() |
|
|
|
document.body.removeChild(aLink) //下载完成移除元素 |
|
|
|
window.URL.revokeObjectURL(url) //释放掉blob对象 |
|
|
|
this.$message.success('导出成功') |
|
|
|
this.$emit('close') |
|
|
|
} else this.$message.error('下载失败') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|