提交 184311f7 authored 作者: yaoxinguo's avatar yaoxinguo

通用方法优化

上级 a68f0416
......@@ -17,10 +17,14 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token';
* rowSpanData 列合并数据,colSpanData行合并数据
* */
export function getSpanJson(mergeKey, data, eliminateStr = []) {
return {
rowSpanData: getRowSpanJson(mergeKey, data, eliminateStr),
colSpanData: getColSpanJson(mergeKey, data, eliminateStr),
};
try {
return {
rowSpanData: getRowSpanJson(mergeKey, data, eliminateStr),
colSpanData: getColSpanJson(mergeKey, data, eliminateStr),
};
} catch (err) {
console.table(err);
}
}
function getRowSpanJson(cloumnNames, data, eliminateStr = []) {
......@@ -120,6 +124,7 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
* columnsHeight 行数
* */
export function getColumns(columns) {
const uj = {
t: 1,
v: '序号',
......@@ -254,7 +259,7 @@ export function getColumnsSqlKeyRealize({
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 200,
colWidths: 250,
},
head: {
font: {
......@@ -267,23 +272,27 @@ export function getColumnsSqlKeyRealize({
if (styles) {
content.styles = styles;
}
let getFileData = giveFilePostDataInfoForTrue(
{
content: JSON.stringify(content),
title: fileName,
},
`${queryOauthActionPath() + '/DataObjApi/exportCustom'}`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
fileName,
ext,
);
try {
let getFileData = giveFilePostDataInfoForTrue(
{
content: JSON.stringify(content),
title: fileName,
},
`${queryOauthActionPath() + '/DataObjApi/exportCustom'}`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
fileName,
ext,
);
} catch (err) {
console.table(err);
}
}
/**
......@@ -312,39 +321,44 @@ export function getColumnsDataRealize({
let { colSpanData, rowSpanData } = getSpanJson(mergeKey, data, eliminateStr);
// 处理数据
let bodyData = [];
let dataMerges = [];
const uj = {
t: 1,
v: '序号',
s: 'header',
};
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);
});
// 处理合并数据
let dataMerges = [];
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]);
}
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);
});
colSpanData[mv].forEach((cv, ci) => {
if (cv > 1) {
//合并表格的 开始行、结束行、开始列、结束列
let rowIndex = columnsKey.indexOf(mv);
dataMerges.push([columnsHeight + ci, columnsHeight + ci, rowIndex, rowIndex + cv - 1]);
}
// 处理合并数据
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(err);
}
let content = {
sheets: [
......@@ -368,7 +382,7 @@ export function getColumnsDataRealize({
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true,
rowHeights: 20,
colWidths: 200,
colWidths: 250,
},
head: {
font: {
......@@ -381,29 +395,39 @@ export function getColumnsDataRealize({
if (styles) {
content.styles = styles;
}
let getFileData = giveFilePostDataInfoForTrue(
{
content: JSON.stringify(content),
title: fileName,
},
`${queryOauthActionPath() + '/DataObjApi/exportCustom'}`,
);
let token = localStorage.getItem('antd-pro-token-onestop');
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
fileName,
ext,
);
try {
let getFileData = giveFilePostDataInfoForTrue(
{
content: JSON.stringify(content),
title: fileName,
},
`${queryOauthActionPath() + '/DataObjApi/exportCustom'}`,
);
let token = localStorage.getItem('antd-pro-token-onestop');
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
fileName,
ext,
);
} catch (err) {
console.table(err);
}
}
// ant列表组件合并表格 render属性,合并纵向、横向。
export function renderContentAll(value, row, index, key, spanData, cloumnNames = []) {
let colSpan = spanData.colSpanData[key][index];// 横向合并
let rowSpan = spanData.rowSpanData[key][index];// 纵向合并
let colSpan, rowSpan = null;
try {
colSpan = spanData.colSpanData[key][index];// 横向合并
rowSpan = spanData.rowSpanData[key][index];// 纵向合并
} catch (err) {
console.table(err);
}
const obj = {
children: value,
props: {
......@@ -413,9 +437,24 @@ export function renderContentAll(value, row, index, key, spanData, cloumnNames =
};
return obj;
}
// ant列表组件合并表格 render属性,合并纵向。
export function renderContentRow(value, row, index, key, spanData, cloumnNames = []) {
let rowSpan = spanData.rowSpanData[key][index];// 纵向合并
// ant列表组件合并表格 render属性,合并纵向。 meanwhileKey :key 是本身字段key,value 是同步的字段key
export function renderContentRow(value, row, index, key, spanData, cloumnNames = [], meanwhileKey = {}) {
let colSpan, rowSpan = null;
try {
if (cloumnNames.indexOf(key) !== -1) {
rowSpan = spanData.rowSpanData[key][index];// 纵向合并
} else {
if (key in meanwhileKey && meanwhileKey[key]) {
let meanwhileKeyValue = meanwhileKey[key];
rowSpan = spanData.rowSpanData[meanwhileKeyValue][index];// 同步字段 的纵向合并
} else {
rowSpan = 1;
}
}
} catch (err) {
console.table(err);
}
const obj = {
children: value,
props: {
......@@ -446,30 +485,34 @@ export function getWord({
listConfig = {},
ext = 'docx',
}) {
try {
let getFileData = giveFilePostDataInfoForTrue(
{
templatePath: templatePath,
params: JSON.stringify({
...listConfig,
...setObjectKey(params),
}),
title: `${title}.${ext}`,
allValues: JSON.stringify({ ...allValues }),
},
queryOauthActionPath() + `/DataColumnApi/exportWord`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
title,
ext,
);
} catch (err) {
console.table(err);
}
//可更新的
//可更新的
let getFileData = giveFilePostDataInfoForTrue(
{
templatePath: templatePath,
params: JSON.stringify({
...listConfig,
...setObjectKey(params),
}),
title: `${title}.${ext}`,
allValues: JSON.stringify({ ...allValues }),
},
queryOauthActionPath() + `/DataColumnApi/exportWord`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
title,
ext,
);
function setObjectKey(data) {
return (
Object.keys(data)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论