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