Browse Source

2026-10-20

导出优化
master
fengyuan_yang 1 month ago
parent
commit
dd1cd41f2d
  1. 3
      src/api/shopOrder/productionReport.js
  2. 112
      src/views/modules/shopOrder/productionReport/searchSfdcRollsReport.vue

3
src/api/shopOrder/productionReport.js

@ -24,6 +24,9 @@ export const searchProductionLineOutputReport = data => createAPI(`/productionRe
// 订单产出标签报表--查询
export const searchSfdcRollsReport = data => createAPI(`/productionReport/searchSfdcRollsReport`,'post',data)
// 订单产出标签报表--导出
export const exportSfdcRollsReport = data => createAPI(`/productionReport/exportSfdcRollsReport`,'post',data, 'download')
// 订单产出标签报表--保存属性变更
export const updateSfdcRollsAttribute = data => createAPI(`/productionReport/updateSfdcRollsAttribute`,'post',data)

112
src/views/modules/shopOrder/productionReport/searchSfdcRollsReport.vue

@ -150,20 +150,7 @@
<el-col :span="24">
<div class="search-actions">
<el-button type="primary" icon="el-icon-search" @click="getData()">{{ buttons.search }}</el-button>
<download-excel
:fields="fields()"
:data="exportData"
type="xls"
:name="exportName"
:header="exportHeader"
:footer="exportFooter"
:fetch="createExportData"
:before-generate="startDownload"
:before-finish="finishDownload"
worksheet="导出信息"
class="el-button el-button--primary el-button--medium">
<i class="el-icon-download"></i> {{ buttons.download }}
</download-excel>
<el-button type="primary" icon="el-icon-download" @click="exportSfdcRollsData">{{ buttons.download }}</el-button>
<el-button type="primary" icon="el-icon-printer" @click="printLabelModel()">打印</el-button>
<el-button type="warning" icon="el-icon-edit" @click="openAttributeChangeDialog()">属性变动</el-button>
<div class="summary-bar">
@ -509,7 +496,7 @@ import {
searchFunctionButtonList,
} from "@/api/sysLanguage.js"
import {searchSfdcRollsReport, updateSfdcRollsAttribute, executeSfdcRollsReport} from "../../../../api/shopOrder/productionReport";
import {searchSfdcRollsReport, exportSfdcRollsReport, updateSfdcRollsAttribute, executeSfdcRollsReport} from "../../../../api/shopOrder/productionReport";
import {updateInventoryStockAttribute} from "../../../../api/wms/wms";
import getLodop from '@/utils/LodopFuncs.js';
import {getPartLabelTemplateList, callUspPartLabelTemplate} from '@/api/wms/wms.js';
@ -581,12 +568,7 @@ import labelPrintTemplates from '@/mixins/labelPrintTemplates.js';
objectType: 'label'
},
tagNo:'',
// 导出 start
exportData: [],
exportName: "产线产量报告"+this.dayjs().format('YYYYMMDDHHmmss'),
exportHeader: ["产线产量报告"],
exportFooter: [],
// 导出 end
exportName: "订单产出标签统计"+this.dayjs().format('YYYYMMDDHHmmss'),
tableHeight: 400,
modelFlag:false,
modelInputFlag:true,
@ -1299,20 +1281,46 @@ import labelPrintTemplates from '@/mixins/labelPrintTemplates.js';
this.pageIndex = val;
this.getData();
},
//导出excel
async createExportData() {
async exportSfdcRollsData() {
this.startDownload()
const params = {
...this.searchData
}
try {
const params = {
...this.searchData,
page: 0,
limit: 1000000
};
const { data } = await searchSfdcRollsReport(params);
return data.rows || [];
const response = await exportSfdcRollsReport(params)
const fileBlob = response && response.data ? response.data : null
if (!fileBlob || fileBlob.size === 0) {
throw new Error('导出文件为空')
}
const contentType = fileBlob.type || ''
if (contentType.indexOf('application/json') > -1) {
const text = await fileBlob.text()
let errMsg = '导出失败'
try {
const json = JSON.parse(text)
errMsg = json.msg || json.message || errMsg
} catch (e) {
errMsg = text || errMsg
}
throw new Error(errMsg)
}
const disposition = response.headers && response.headers['content-disposition']
const defaultFileName = `${this.exportName}.xlsx`
const fileName = this.parseDownloadFileName(disposition) || defaultFileName
const linkNode = document.createElement('a')
const url = URL.createObjectURL(fileBlob)
linkNode.href = url
linkNode.download = fileName
linkNode.style.display = 'none'
document.body.appendChild(linkNode)
linkNode.click()
document.body.removeChild(linkNode)
URL.revokeObjectURL(url)
this.$message.success('导出成功')
} catch (error) {
console.error('获取导出数据失败:', error);
this.$message.error('获取导出数据失败!');
return [];
this.$message.error('导出失败:' + (error.message || '请稍后重试'))
} finally {
this.finishDownload()
}
},
selectionChangeHandle(val){
@ -1697,6 +1705,7 @@ import labelPrintTemplates from '@/mixins/labelPrintTemplates.js';
});
},
startDownload() {
this.exportName = "订单产出标签统计" + this.dayjs().format('YYYYMMDDHHmmss')
this._exportLoading = this.$loading({
lock: true,
text: '正在导出数据,请稍候...',
@ -1710,28 +1719,27 @@ import labelPrintTemplates from '@/mixins/labelPrintTemplates.js';
this._exportLoading = null
}
},
formatExportText(value) {
if (value === '' || value === null || value === undefined) {
parseDownloadFileName(disposition) {
if (!disposition) {
return ''
}
const safeValue = String(value).replace(/"/g, '""')
return `="${safeValue}"`
},
fields() {
const fieldMap = {}
this.columnList.forEach(item => {
if (item.columnProp === 'packingList') {
fieldMap[item.columnLabel] = {
field: item.columnProp,
callback: value => this.formatExportText(value)
}
return
}
fieldMap[item.columnLabel] = item.columnProp
})
return fieldMap
let fileName = ''
const utf8Match = disposition.match(/filename\*=UTF-8''([^;]+)/i)
if (utf8Match && utf8Match[1]) {
fileName = utf8Match[1]
} else {
const normalMatch = disposition.match(/filename="?([^"]+)"?/i)
fileName = normalMatch && normalMatch[1] ? normalMatch[1] : ''
}
if (!fileName) {
return ''
}
try {
return decodeURIComponent(fileName)
} catch (e) {
return fileName
}
},
// 导出 end
//多语言
getMultiLanguageList() {
//首先查询当前按钮的多语言

Loading…
Cancel
Save