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

通用方法优化

上级 a68f0416
...@@ -17,10 +17,14 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token'; ...@@ -17,10 +17,14 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token';
* rowSpanData 列合并数据,colSpanData行合并数据 * rowSpanData 列合并数据,colSpanData行合并数据
* */ * */
export function getSpanJson(mergeKey, data, eliminateStr = []) { export function getSpanJson(mergeKey, data, eliminateStr = []) {
try {
return { return {
rowSpanData: getRowSpanJson(mergeKey, data, eliminateStr), rowSpanData: getRowSpanJson(mergeKey, data, eliminateStr),
colSpanData: getColSpanJson(mergeKey, data, eliminateStr), colSpanData: getColSpanJson(mergeKey, data, eliminateStr),
}; };
} catch (err) {
console.table(err);
}
} }
function getRowSpanJson(cloumnNames, data, eliminateStr = []) { function getRowSpanJson(cloumnNames, data, eliminateStr = []) {
...@@ -120,6 +124,7 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { ...@@ -120,6 +124,7 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
* columnsHeight 行数 * columnsHeight 行数
* */ * */
export function getColumns(columns) { export function getColumns(columns) {
const uj = { const uj = {
t: 1, t: 1,
v: '序号', v: '序号',
...@@ -254,7 +259,7 @@ export function getColumnsSqlKeyRealize({ ...@@ -254,7 +259,7 @@ export function getColumnsSqlKeyRealize({
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true, wrapText: true,
rowHeights: 20, rowHeights: 20,
colWidths: 200, colWidths: 250,
}, },
head: { head: {
font: { font: {
...@@ -267,6 +272,7 @@ export function getColumnsSqlKeyRealize({ ...@@ -267,6 +272,7 @@ export function getColumnsSqlKeyRealize({
if (styles) { if (styles) {
content.styles = styles; content.styles = styles;
} }
try {
let getFileData = giveFilePostDataInfoForTrue( let getFileData = giveFilePostDataInfoForTrue(
{ {
content: JSON.stringify(content), content: JSON.stringify(content),
...@@ -284,6 +290,9 @@ export function getColumnsSqlKeyRealize({ ...@@ -284,6 +290,9 @@ export function getColumnsSqlKeyRealize({
fileName, fileName,
ext, ext,
); );
} catch (err) {
console.table(err);
}
} }
/** /**
...@@ -312,11 +321,13 @@ export function getColumnsDataRealize({ ...@@ -312,11 +321,13 @@ export function getColumnsDataRealize({
let { colSpanData, rowSpanData } = getSpanJson(mergeKey, data, eliminateStr); let { colSpanData, rowSpanData } = getSpanJson(mergeKey, data, eliminateStr);
// 处理数据 // 处理数据
let bodyData = []; let bodyData = [];
let dataMerges = [];
const uj = { const uj = {
t: 1, t: 1,
v: '序号', v: '序号',
s: 'header', s: 'header',
}; };
try {
data.forEach((dv, di) => { data.forEach((dv, di) => {
let nowArroy = new Array(columnsKey.length).fill({}); let nowArroy = new Array(columnsKey.length).fill({});
columnsKey.forEach((av, ai) => { columnsKey.forEach((av, ai) => {
...@@ -328,7 +339,6 @@ export function getColumnsDataRealize({ ...@@ -328,7 +339,6 @@ export function getColumnsDataRealize({
bodyData.push(nowArroy); bodyData.push(nowArroy);
}); });
// 处理合并数据 // 处理合并数据
let dataMerges = [];
mergeKey.forEach((mv, mi) => { mergeKey.forEach((mv, mi) => {
rowSpanData[mv].forEach((cv, ci) => { rowSpanData[mv].forEach((cv, ci) => {
if (cv > 1) { if (cv > 1) {
...@@ -345,6 +355,10 @@ export function getColumnsDataRealize({ ...@@ -345,6 +355,10 @@ export function getColumnsDataRealize({
} }
}); });
}); });
} catch (err) {
console.table(err);
}
let content = { let content = {
sheets: [ sheets: [
...@@ -368,7 +382,7 @@ export function getColumnsDataRealize({ ...@@ -368,7 +382,7 @@ export function getColumnsDataRealize({
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
wrapText: true, wrapText: true,
rowHeights: 20, rowHeights: 20,
colWidths: 200, colWidths: 250,
}, },
head: { head: {
font: { font: {
...@@ -381,6 +395,7 @@ export function getColumnsDataRealize({ ...@@ -381,6 +395,7 @@ export function getColumnsDataRealize({
if (styles) { if (styles) {
content.styles = styles; content.styles = styles;
} }
try {
let getFileData = giveFilePostDataInfoForTrue( let getFileData = giveFilePostDataInfoForTrue(
{ {
content: JSON.stringify(content), content: JSON.stringify(content),
...@@ -398,12 +413,21 @@ export function getColumnsDataRealize({ ...@@ -398,12 +413,21 @@ export function getColumnsDataRealize({
fileName, fileName,
ext, ext,
); );
} catch (err) {
console.table(err);
}
} }
// ant列表组件合并表格 render属性,合并纵向、横向。 // ant列表组件合并表格 render属性,合并纵向、横向。
export function renderContentAll(value, row, index, key, spanData, cloumnNames = []) { export function renderContentAll(value, row, index, key, spanData, cloumnNames = []) {
let colSpan = spanData.colSpanData[key][index];// 横向合并 let colSpan, rowSpan = null;
let rowSpan = spanData.rowSpanData[key][index];// 纵向合并 try {
colSpan = spanData.colSpanData[key][index];// 横向合并
rowSpan = spanData.rowSpanData[key][index];// 纵向合并
} catch (err) {
console.table(err);
}
const obj = { const obj = {
children: value, children: value,
props: { props: {
...@@ -413,9 +437,24 @@ export function renderContentAll(value, row, index, key, spanData, cloumnNames = ...@@ -413,9 +437,24 @@ export function renderContentAll(value, row, index, key, spanData, cloumnNames =
}; };
return obj; return obj;
} }
// ant列表组件合并表格 render属性,合并纵向。
export function renderContentRow(value, row, index, key, spanData, cloumnNames = []) { // ant列表组件合并表格 render属性,合并纵向。 meanwhileKey :key 是本身字段key,value 是同步的字段key
let rowSpan = spanData.rowSpanData[key][index];// 纵向合并 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 = { const obj = {
children: value, children: value,
props: { props: {
...@@ -446,8 +485,7 @@ export function getWord({ ...@@ -446,8 +485,7 @@ export function getWord({
listConfig = {}, listConfig = {},
ext = 'docx', ext = 'docx',
}) { }) {
try {
//可更新的
let getFileData = giveFilePostDataInfoForTrue( let getFileData = giveFilePostDataInfoForTrue(
{ {
templatePath: templatePath, templatePath: templatePath,
...@@ -470,6 +508,11 @@ export function getWord({ ...@@ -470,6 +508,11 @@ export function getWord({
title, title,
ext, ext,
); );
} catch (err) {
console.table(err);
}
//可更新的
function setObjectKey(data) { function setObjectKey(data) {
return ( return (
Object.keys(data) Object.keys(data)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论