Browse Source

新增导出

dev-xx
qb 11 months ago
parent
commit
928be0c080
  1. 2
      src/utils/util.js
  2. 71
      src/views/distribution/deliverylist/distributionDeliveryListdis.vue

2
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]') {

71
src/views/distribution/deliverylist/distributionDeliveryListdis.vue

@ -186,13 +186,13 @@
<!-- 打印模块 -->
<el-dialog title="二维码" :visible.sync="isShow" width="780px" v-model="isShow">
<div>
<div ref="tableRef">
<div v-html="html"></div>
</div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="printTemplate"> </el-button>
<el-button type="primary" @click="isShow = false"> </el-button>
<el-button @click="isShow = false"> </el-button>
<el-button type="primary" @click="handleExport"> </el-button>
<el-button @click="isShow = false"> </el-button>
</span>
</el-dialog>
</div>
@ -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');
},
},
};
</script>

Loading…
Cancel
Save