commit
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user