This commit is contained in:
zhutianqi
2021-07-09 17:27:05 +08:00
parent 57a02d5333
commit a5f2bff546
14 changed files with 2604 additions and 30 deletions
+41
View File
@@ -282,6 +282,47 @@ export default {
exeFun.call(this, err)
})
},
downloadFile (url, param, fileName) {
_axios({
method: 'post',
url,
data: param,
responseType: 'blob'
}).then(
res => {
const data = res.data
const r = new FileReader()
r.onload = function () {
try {
const resData = JSON.parse(this.result)
} catch (err) {
// 下载正常处理
// 兼容ie11
if (window.navigator.msSaveOrOpenBlob) {
try {
const blobObject = new Blob([data])
window.navigator.msSaveOrOpenBlob(blobObject, fileName)
} catch (e) {
console.log(e)
}
return
}
// a标签实现下载
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
resolve(fileName)
}
}
r.readAsText(data) // FileReader的API
}).catch(res => {
console.log(res)
})
},
/**
* @description: delete方法
* @author: chenxiaoxi