From ee3a397b90ebc3ec50719b60e2b912f10d3d0ab6 Mon Sep 17 00:00:00 2001 From: ljlong_2630 Date: Fri, 15 Nov 2024 10:26:36 +0800 Subject: [PATCH] =?UTF-8?q?YT-978=EF=BC=8CYT-914=EF=BC=9A=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E4=BB=93=E5=BA=93=E4=BB=A3=E7=A0=81=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=92=8C=E5=B7=AE=E5=BC=82=E6=95=B0=E6=8D=AE=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + .../ImportForm/src/ImportFormStep.vue | 34 ++++++++- .../callmaterials/callmaterials.data.ts | 70 +++++++++---------- .../deliverRecordMain.data.ts | 5 ++ 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index e2fe74cd1..2e2eb6e88 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "vue-types": "^5.1.1", "vuedraggable": "^4.1.0", "web-storage-cache": "^1.1.1", + "xlsx": "^0.18.5", "xml-js": "^1.6.11" }, "devDependencies": { diff --git a/src/components/ImportForm/src/ImportFormStep.vue b/src/components/ImportForm/src/ImportFormStep.vue index 616527ac4..832e09cee 100644 --- a/src/components/ImportForm/src/ImportFormStep.vue +++ b/src/components/ImportForm/src/ImportFormStep.vue @@ -82,7 +82,7 @@ {{ t('ts.下载模板') }} - + {{ t('ts.下载差异数据') }} @@ -101,6 +101,7 @@ import download from '@/utils/download' import { getBaseUrl } from '@/utils/systemParam' import { UploadFilled, List, CircleCheckFilled,WarningFilled } from '@element-plus/icons-vue' import { waitForDebugger } from 'node:inspector/promises' +import * as XLSX from 'xlsx'; defineOptions({ name: 'ImportForm' }) @@ -432,6 +433,37 @@ const importTemplate = () => { const res = importTemplateData.value.templateUrl download.excel(res, importTemplateData.value.templateTitle) } + +const downloadDifferenceData = () => { + if (props.tableObject.tableList.length === 0) { + message.warning('没有可下载的差异数据'); + return; + } + + // 获取当前使用的列定义 + const columns = currentColumns.value; + + // 创建工作簿和工作表,使用原始数据 + const wb = XLSX.utils.book_new(); + const ws = XLSX.utils.json_to_sheet(props.tableObject.tableList); + + // 替换表头为中文; + columns.forEach((col, index) => { + const cellAddress = XLSX.utils.encode_cell({ r: 0, c: index }); + if (ws[cellAddress]) { + ws[cellAddress].v = col.label; + } + }); + + // 设置列宽(可选) + const colWidth = columns.map(() => ({ wch: 20 })); + ws['!cols'] = colWidth; + + // 添加工作表到工作簿并下载 + XLSX.utils.book_append_sheet(wb, ws, "差异数据"); + const timestamp = new Date().getTime(); + XLSX.writeFile(wb, `差异数据_${timestamp}.xlsx`); +}