This commit is contained in:
parent
25de7d3510
commit
de41f8a4cf
|
|
@ -255,7 +255,7 @@ export default {
|
|||
|
||||
// 下载
|
||||
onHandleDownload() {
|
||||
this.download('material-mall/decChange/exportDetails', { id: this.recordId }, `出库记录单.xlsx`)
|
||||
this.download('material-mall/decChange/exportDetailsRepair', { id: this.recordId }, `维修记录单.xlsx`)
|
||||
},
|
||||
|
||||
// 打印
|
||||
|
|
|
|||
|
|
@ -262,42 +262,9 @@ export default {
|
|||
)
|
||||
},
|
||||
|
||||
// 下载PDF方法
|
||||
// 下载
|
||||
onHandleDownload() {
|
||||
this.downloadPDF('material-mall/decChange/exportDetails', { id: this.recordId }, '出库记录单.pdf');
|
||||
},
|
||||
|
||||
// 封装PDF下载逻辑
|
||||
async downloadPDF(url, params, fileName) {
|
||||
try {
|
||||
// 关键:设置responseType为blob(二进制流)
|
||||
const response = await this.$axios({
|
||||
method: 'post',
|
||||
url: url,
|
||||
data: params, // POST请求参数
|
||||
responseType: 'blob', // 必须指定为blob
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8' // 匹配后端接收格式
|
||||
}
|
||||
});
|
||||
|
||||
// 创建下载链接
|
||||
const blob = new Blob([response.data], { type: 'application/pdf' });
|
||||
const downloadUrl = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl;
|
||||
link.download = fileName; // 文件名
|
||||
document.body.appendChild(link);
|
||||
link.click(); // 触发下载
|
||||
|
||||
// 释放资源
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(downloadUrl);
|
||||
|
||||
this.$message.success('PDF导出成功!');
|
||||
} catch (error) {
|
||||
this.$message.error('PDF导出失败:' + (error.message || '未知错误'));
|
||||
}
|
||||
this.download('material-mall/decChange/exportDetails', { id: this.recordId }, `出库记录单.xlsx`)
|
||||
},
|
||||
|
||||
// 打印
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ export default {
|
|||
|
||||
// 下载
|
||||
onHandleDownload() {
|
||||
this.download('material-mall/decChange/exportDetails', { id: this.recordId }, `出库记录单.xlsx`)
|
||||
this.download('material-mall/decChange/exportDetailsRetire', { id: this.recordId }, `退役记录单.xlsx`)
|
||||
},
|
||||
|
||||
// 打印
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ export default {
|
|||
|
||||
// 下载
|
||||
onHandleDownload() {
|
||||
this.download('material-mall/decChange/exportDetails', { id: this.recordId }, `出库记录单.xlsx`)
|
||||
this.download('material-mall/decChange/exportDetails', { id: this.recordId }, `退库记录单.xlsx`)
|
||||
},
|
||||
|
||||
// 打印
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@
|
|||
</el-col>
|
||||
<el-button
|
||||
icon="el-icon-download"
|
||||
style="margin-left: 1250px"
|
||||
style="margin-left: 1320px"
|
||||
type="primary"
|
||||
size="mini"
|
||||
@click="handleExport"
|
||||
|
|
|
|||
Loading…
Reference in New Issue