未结算报表导出zip
This commit is contained in:
parent
dc7a03c2f8
commit
71f6bba93f
|
|
@ -228,40 +228,42 @@ export function downloadJson(url, params, filename, config) {
|
|||
|
||||
// 通用下载方法
|
||||
export function downloadZip(url, params, filename, config) {
|
||||
downloadLoadingInstance = Loading.service({
|
||||
text: '正在下载数据,请稍候',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
})
|
||||
return service
|
||||
.post(url, params, {
|
||||
transformRequest: [
|
||||
(params) => {
|
||||
return params
|
||||
},
|
||||
],
|
||||
headers: { 'Content-Type': 'application/json',encryptResponse: false },
|
||||
responseType: 'blob',
|
||||
...config,
|
||||
})
|
||||
.then(async (data) => {
|
||||
const isBlob = blobValidate(data)
|
||||
if (isBlob) {
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, filename)
|
||||
} else {
|
||||
const resText = await data.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg =
|
||||
errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
Message.error(errMsg)
|
||||
}
|
||||
downloadLoadingInstance.close()
|
||||
})
|
||||
.catch((r) => {
|
||||
console.error(r)
|
||||
Message.error('下载文件出现错误,请联系管理员!')
|
||||
downloadLoadingInstance.close()
|
||||
})
|
||||
}
|
||||
// downloadLoadingInstance = Loading.service({
|
||||
// text: '正在下载数据,请稍候',
|
||||
// spinner: 'el-icon-loading',
|
||||
// background: 'rgba(0, 0, 0, 0.7)',
|
||||
// })
|
||||
return service
|
||||
.post(url, params, {
|
||||
transformRequest: [
|
||||
(params) => {
|
||||
return params
|
||||
},
|
||||
],
|
||||
headers: { 'Content-Type': 'application/json', encryptResponse: false },
|
||||
responseType: 'blob',
|
||||
// 支持传入onDownloadProgress回调
|
||||
...(config && config.onDownloadProgress ? { onDownloadProgress: config.onDownloadProgress } : {}),
|
||||
...config,
|
||||
})
|
||||
.then(async (data) => {
|
||||
const isBlob = blobValidate(data)
|
||||
if (isBlob) {
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, filename)
|
||||
} else {
|
||||
const resText = await data.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg =
|
||||
errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
Message.error(errMsg)
|
||||
}
|
||||
// downloadLoadingInstance.close()
|
||||
})
|
||||
.catch((r) => {
|
||||
console.error(r)
|
||||
Message.error('下载文件出现错误,请联系管理员!')
|
||||
// downloadLoadingInstance.close()
|
||||
})
|
||||
}
|
||||
export default service
|
||||
|
|
|
|||
|
|
@ -931,10 +931,10 @@ export default {
|
|||
})
|
||||
this.totalItems = param.length;
|
||||
|
||||
const taskId = crypto.randomUUID()
|
||||
const taskId = null
|
||||
const payload = {
|
||||
list: param,
|
||||
taskId:taskId,
|
||||
taskId:null,
|
||||
zipName: `未结算批量明细导出_${new Date().getTime()}`,
|
||||
stream: true
|
||||
};
|
||||
|
|
@ -973,31 +973,17 @@ export default {
|
|||
this.progressText = '正在连接服务器...';
|
||||
|
||||
// 使用原始的request方法
|
||||
const response = await request({
|
||||
url: '/material/slt_agreement_info/dlExProgress',
|
||||
method: 'POST',
|
||||
data: payload,
|
||||
responseType: 'blob',
|
||||
timeout: 0,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
this.handleDownloadProgress(progressEvent);
|
||||
}
|
||||
});
|
||||
|
||||
// 创建下载链接
|
||||
const blob = new Blob([response]);
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
a.download = `${payload.zipName}.zip`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// 清理
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
|
||||
await this.downloadZip(
|
||||
'/material/slt_agreement_info/dlExProgress',
|
||||
JSON.stringify(payload),
|
||||
`${payload.zipName}.zip`,
|
||||
{
|
||||
timeout: 0,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
this.handleDownloadProgress(progressEvent);
|
||||
}
|
||||
}
|
||||
)
|
||||
// 完成状态
|
||||
this.handleDownloadComplete();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue