项目为符合项导出

This commit is contained in:
zhn
2022-07-12 16:45:38 +08:00
parent d3de930960
commit 5ef30c2eb2
6 changed files with 105 additions and 20 deletions
+87 -1
View File
@@ -134,7 +134,14 @@ export function downFile(url, parameter) {
responseType: 'blob'
})
}
export function downFilePost(url, parameter) {
return axios({
url: url,
data: parameter,
method: 'post',
responseType: 'blob'
})
}
/**
* 下载文件
* @param url 文件路径
@@ -222,6 +229,85 @@ export function downloadFile(url, fileName, parameter, callback) {
})
}
export function downloadFilePost(url, fileName, parameter, callback) {
let langCn = localStorage.language
// 默认中文
let isTrue
if (langCn == 'en-us') {
isTrue = true
} else if (langCn == 'zh-cn') {
isTrue = false
}
index.showDrawer({
loading: true,
isTrue: isTrue
})
return downFilePost(url, parameter).then((data) => {
let fileReader = new FileReader()
fileReader.onload = function(event) {
try {
let jsonData = JSON.parse(event.target.result)
if (jsonData.message.includes('token')) {
index.showDrawer({
loading: false,
isTrue: isTrue
})
Modal.error({
title: '登录已过期',
content: '很抱歉登录已过期请重新登录',
okText: '重新登录',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
try {
let path = window.document.location.pathname
if (path != '/' && path.indexOf('/user/login') == -1) {
window.location.reload()
}
} catch (e) {
window.location.reload()
}
})
}
})
} else {
if (!jsonData.success) {
index.showDrawer({
loading: false,
isTrue: isTrue
})
Vue.prototype['$message'].warning(jsonData.message)
}
}
} catch (e) {
if (!data || data.size === 0) {
Vue.prototype['$message'].warning('文件下载失败')
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data]), fileName)
} else {
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()
document.body.removeChild(link) //下载完成移除元素
window.URL.revokeObjectURL(url) //释放掉blob对象
}
index.showDrawer({
loading: false,
isTrue: isTrue
})
callback && callback()
}
}
fileReader.readAsText(data)
})
}
/**
* 文件上传 用于富文本上传图片
* @param url