diff --git a/src/utils/util.js b/src/utils/util.js index 46f20322..334b1865 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -468,14 +468,12 @@ export const getWinHeight = () => { export const setNodeHeight = async (_node, _height = '', isDelayed = false) => { const _fn = async (_node, _height) => { await nextTick(); - console.log('getWinHeight() :>> ', getWinHeight()); const _defaultHeight = getWinHeight(); // 判断是否传入的是数组 const _type = Object.prototype.toString.call(_node); console.log('_type :>> ', _type); // 传入数组时 if (_type === '[object NodeList]') { - console.log('333 :>> ', 333); _node.forEach(val => { const _itemType = Object.prototype.toString.call(val); if (_itemType === '[object HTMLDivElement]') { diff --git a/src/views/distribution/deliverylist/distributionDeliveryListdis.vue b/src/views/distribution/deliverylist/distributionDeliveryListdis.vue index 2c03e293..69d1e623 100644 --- a/src/views/distribution/deliverylist/distributionDeliveryListdis.vue +++ b/src/views/distribution/deliverylist/distributionDeliveryListdis.vue @@ -186,13 +186,13 @@ -
+
打 印 - 确 定 - 取 消 + 导 出 + 关 闭
@@ -313,8 +313,9 @@ import { getVehicleList } from '@/api/basicdata/basicdataVehicle'; import { getDriverList } from '@/api/basicdata/basicdataDriverArtery'; import print from '@/utils/print'; import { getBillLadingExport } from '@/api/distribution/distrilbutionBillLading'; -import { downloadXls } from '@/utils/util'; +import { downloadXls, getObjType } from '@/utils/util'; import { ElMessage, ElMessageBox } from 'element-plus'; +import * as XLSX from 'xlsx'; export default { data() { return { @@ -1312,6 +1313,68 @@ export default { printTemplate() { print(); }, + /** 导出 */ + handleExport() { + console.log('this.$refs.tableRef :>> ', this.$refs.tableRef); + + const table = this.$refs.tableRef; + + /* 将表格转换为 Workbook 对象 */ + const wb = XLSX.utils.table_to_book(table); + + console.log('wb :>> ', wb); + + wb.Sheets.Sheet1; + + //单元格外侧框线 + const borderAll = { + top: { + style: 'thin', + }, + bottom: { + style: 'thin', + }, + left: { + style: 'thin', + }, + right: { + style: 'thin', + }, + }; + + for (const key in wb.Sheets.Sheet1) { + const item = wb.Sheets.Sheet1[key]; + + const type = getObjType(item); + + console.log('type :>> ', type); + + if (type !== 'object') continue; + + item.s = { + border: borderAll, + font: { + // name: "微软雅黑", + // sz: 16, + color: { rgb: '000000' }, + bold: true, + italic: false, + underline: false, + }, + fill: { + fgColor: { rgb: 'C5D9F1' }, + }, + alignment: { + horizontal: 'center', + vertical: 'center', + wrapText: false, // 自动换行 + }, + }; + } + + /* 导出 Workbook 到 Excel 文件 */ + XLSX.writeFile(wb, 'data.xlsx'); + }, }, };