提交 4f0e04fd authored 作者: 姚鑫国's avatar 姚鑫国

新增自定义导出excl方法 getCustomDataRealize

上级 9667ac8f
......@@ -7,7 +7,9 @@ import {
getSpanJson,
getColumns,
getColumnsData,
getCustomData,
getColumnsDataRealize,
getCustomDataRealize,
getColumnsSqlKeyRealize,
getCustomSqlKeyRealize,
getWord,
......@@ -44,7 +46,9 @@ export function giveSmartFormGlobalProps({
getSpanJson,
getColumns,
getColumnsDataRealize,
getCustomDataRealize,
getColumnsData,
getCustomData,
getColumnsSqlKeyRealize,
getCustomSqlKeyRealize,
getWord,
......@@ -66,8 +70,12 @@ export function giveSmartFormGlobalProps({
`获取ant表头的属性 ;参数->columns : ant的表头`,
'getColumnsData({data, mergeKey, columns, styles, defect, fileName, ext , eliminateStr})':
`获取列表合并的数据;参数-> 前三个必填data, mergeKey, columns`,
'getCustomData({data, mergeKey, columnsList,columnsMerges,columnsKey, styles, defect, fileName, ext , eliminateStr})':
`获取列表合并的数据;参数-> 前五个个必填data, mergeKey, columnsList,columnsMerges,columnsKey`,
'getColumnsDataRealize({data, mergeKey, columns, styles, defect, fileName, ext , eliminateStr})':
`下载列表合并的数据;参数-> 前三个必填data, mergeKey, columns`,
'getCustomDataRealize({data, mergeKey,columnsList ,columnsMerges,columnsKey,bottomList,bottomMerges, styles, defect, fileName, ext , eliminateStr})':
`下载列表合并的数据;参数-> 前五个必填data, mergeKey,columnsList ,columnsMerges,columnsKey`,
'getColumnsSqlKeyRealize({sqlKey, columns, styles, fileName, ext})':
`下载列表表头合并的数据;参数->前两个必填sqlKey, columns`,
'getCustomSqlKeyRealize({sqlKey, columnsList,columnsMerges,columnsKey, styles, fileName, ext})':
......
......@@ -8,7 +8,36 @@ import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/local
import moment from 'moment';
const apiUrl = queryOauthActionPath();
const exportStyles = {
header: {
font: {
bold: false,
fontHeightInPoints: 12,
},
alignment: 'CENTER',
borderLeft: 'THIN',
borderTop: 'THIN',
borderBottom: 'THIN',
borderRight: 'THIN',
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 250,
},
head: {
font: {
bold: true,
},
alignment: 'CENTER',
},
};
const uj = {
t: 1,
v: '序号',
s: 'header',
w: 20 //默认值是20像素
};
/**
* 公共函数代码
*
......@@ -151,13 +180,6 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
* */
export function getColumns(columns) {
columns = deepCopy(columns);
const uj = {
t: 1,
v: '序号',
s: 'header',
w: 20 //默认值是20像素
};
let columnsHeight = getColumnsMaxLevel(columns); //递归行数
let columnsKey = [];
const columnsList = new Array(columnsHeight).fill([]);
......@@ -297,29 +319,7 @@ export function getColumnsSqlKeyRealize({
sqlKeyHeader: columnsKey, //sql对应key对应列
},
],
styles: {
header: {
font: {
bold: false,
fontHeightInPoints: 12,
},
alignment: 'CENTER',
borderLeft: 'THIN',
borderTop: 'THIN',
borderBottom: 'THIN',
borderRight: 'THIN',
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 250,
},
head: {
font: {
bold: true,
},
alignment: 'CENTER',
},
},
styles: exportStyles
};
if (styles) {
content.styles = styles;
......@@ -362,7 +362,7 @@ export function getColumnsSqlKeyRealize({
* ext : 导出后缀 目前xecl、dbf
* url : 接口地址
*/
export function getCustomSqlKeyRealize({
export function getCustomSqlKeyRealize({
sqlKey,
columnsList,
columnsMerges,
......@@ -382,29 +382,7 @@ export function getColumnsSqlKeyRealize({
sqlKeyHeader: columnsKey, //sql对应key对应列
},
],
styles: {
header: {
font: {
bold: false,
fontHeightInPoints: 12,
},
alignment: 'CENTER',
borderLeft: 'THIN',
borderTop: 'THIN',
borderBottom: 'THIN',
borderRight: 'THIN',
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 250,
},
head: {
font: {
bold: true,
},
alignment: 'CENTER',
},
},
styles: exportStyles
};
if (styles) {
content.styles = styles;
......@@ -498,6 +476,79 @@ export function getColumnsDataRealize({
}
/**
*
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
* 表头和数据导出(合并表格)
* data : ant基础数据
* columns : ant表头基础数据
* styles : 导出excl样式
* defect : 为null时默认数据
* fileName : 导出文件名
* ext : 导出后缀 目前xecl、dbf
* url : 接口地址
* eliminateRow : 列需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
*
*/
export function getCustomDataRealize({
data = [],
mergeKey = [],
columnsList = [],
columnsMerges = [],
columnsKey = [],
bottomList = [],
bottomMerges = [],
styles,
defect = null,
fileName = '导出文件',
ext = 'xlsx',
eliminateRow = [],
eliminateCol = [],
}) {
let content = getCustomData({
data,
mergeKey,
columnsList,
columnsMerges,
columnsKey,
bottomList,
bottomMerges,
styles,
defect,
fileName,
ext,
eliminateRow,
eliminateCol,
});
if (styles) {
content.styles = styles;
}
try {
let getFileData = giveFilePostDataInfoForTrue(
{
content: JSON.stringify(content),
title: fileName,
},
`${apiUrl + '/DataObjApi/exportCustom'}`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
fileName,
ext,
);
} catch (err) {
console.table("getCustomDataRealize", err);
}
}
/**
*
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
......@@ -545,11 +596,6 @@ export function getColumnsData({
// 处理数据
let bodyData = [];
let dataMerges = [];
const uj = {
t: 1,
v: '序号',
s: 'header',
};
try {
data.forEach((dv, di) => {
let nowArroy = new Array(columnsKey.length).fill({});
......@@ -589,31 +635,126 @@ export function getColumnsData({
merges: [...columnsMerges, ...dataMerges],
},
],
styles: {
header: {
font: {
bold: false,
fontHeightInPoints: 12,
},
alignment: 'CENTER',
borderLeft: 'THIN',
borderTop: 'THIN',
borderBottom: 'THIN',
borderRight: 'THIN',
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 250,
},
head: {
font: {
bold: true,
},
alignment: 'CENTER',
styles: exportStyles
};
if (ext === "docx") {
content.sheets[0] = {
...content.sheets[0],
...docxSheet
}
}
if (styles) {
content.styles = styles;
}
return content
}
/**
*
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
* 表头和数据导出(合并表格)
* data : ant基础数据
* columns : ant表头基础数据
* styles : 导出excl样式
* defect : 为null时默认数据
* fileName : 导出文件名
* ext : 导出后缀 目前xecl、dbf
* url : 接口地址
* eliminateRow : 列需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
*
*/
export function getCustomData({
data = [],
mergeKey = [],
columnsList = [],
columnsMerges = [],
columnsKey = [],
bottomList = [],
bottomMerges = [],
styles,
defect = null,
fileName = '导出文件',
ext = 'xlsx',
eliminateRow = [],
eliminateCol = [],
docxSheet = {},
}) {
data = deepCopy(data);
let columnsHeight = columnsList.length;
let {
colSpanData,
rowSpanData
} = getSpanJson({
mergeKey,
data,
eliminateRow,
eliminateCol
});
// 处理数据
let bodyData = [];
let dataMerges = [];
try {
data.forEach((dv, di) => {
let nowArroy = new Array(columnsKey.length).fill({});
columnsKey.forEach((av, ai) => {
nowArroy[ai] = {
...uj,
v: av in dv && dv[av] != null ? dv[av].toString() : defect || '',
};
});
bodyData.push(nowArroy);
});
// 处理合并数据
mergeKey.forEach((mv, mi) => {
rowSpanData[mv].forEach((cv, ci) => {
if (cv > 1) {
//合并表格的 开始行、结束行、开始列、结束列
let rowIndex = columnsKey.indexOf(mv);
dataMerges.push([columnsHeight + ci, columnsHeight + ci + cv - 1, rowIndex, rowIndex]);
}
});
colSpanData[mv].forEach((cv, ci) => {
if (cv > 1) {
//合并表格的 开始行、结束行、开始列、结束列
let rowIndex = columnsKey.indexOf(mv);
dataMerges.push([columnsHeight + ci, columnsHeight + ci, rowIndex, rowIndex + cv - 1]);
}
});
});
} catch (err) {
console.table("getColumnsData", err);
}
const columnsDataCells = [...columnsList, ...bodyData];
const columnsDataMerges = [...columnsMerges, ...dataMerges];
let newBottomMerges = [];
if (bottomList && bottomList.length > 0) { // 新增底部数据
if (columnsKey.length != bottomList[0].length) {
console.log("bottomList数据列数和表头列数不一致");
return
}
newBottomMerges = bottomMerges.map((v, i) => {
let newV = v;
//合并表格的 开始行、结束行、开始列、结束列
newV[0] += columnsDataCells.length;
newV[1] += columnsDataCells.length;
return v;
});
}
let content = {
sheets: [
{
name: fileName,
cells: [...columnsDataCells, ...bottomList],
merges: [...columnsDataMerges, ...newBottomMerges],
},
},
],
styles: exportStyles
};
if(ext === "docx"){
if (ext === "docx") {
content.sheets[0] = {
...content.sheets[0],
...docxSheet
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论