提交 6e999a0c authored 作者: 钟是志's avatar 钟是志

Merge remote-tracking branch 'origin/master'

...@@ -9,6 +9,8 @@ import { ...@@ -9,6 +9,8 @@ import {
getColumnsDataRealize, getColumnsDataRealize,
getColumnsSqlKeyRealize, getColumnsSqlKeyRealize,
getWord, getWord,
renderContentAll,
renderContentRow,
} from './globalFunction'; } from './globalFunction';
export function giveSmartFormGlobalProps({ export function giveSmartFormGlobalProps({
...@@ -37,14 +39,18 @@ export function giveSmartFormGlobalProps({ ...@@ -37,14 +39,18 @@ export function giveSmartFormGlobalProps({
getColumnsDataRealize, getColumnsDataRealize,
getColumnsSqlKeyRealize, getColumnsSqlKeyRealize,
getWord, getWord,
remark: ` renderContentAll,
giveFilePostDataInfoForTrue(params, url); //将接口参数 二进制文件化 并返回新的接口地址与参数'; renderContentRow,
getSpanJson(mergeKey, data, eliminateStr); //列表获取纵向合并数据 mergeKey : 需要合并的表头key data : 列表数据 eliminateStr : 需要忽略合并的数据 remark: {
getColumns(columns); //获取ant表头的属性 columns : ant的表头 "giveFilePostDataInfoForTrue(params, url) ":`将接口参数 二进制文件化 并返回新的接口地址与参数';`,
getColumnsDataRealize({data, mergeKey, columns, styles, defect, fileName, ext , eliminateStr}); // 下载列表合并的数据,前三个必填data, mergeKey, columns "getSpanJson(mergeKey, data, eliminateStr)":`列表获取纵向合并数据 ;参数-> mergeKey : 需要合并的表头key data : 列表数据 eliminateStr : 需要忽略合并的数据`,
getColumnsSqlKeyRealize({sqlKey, columns, styles, fileName, ext}); // 下载列表表头合并的数据,前两个个必填sqlKey, columns "getColumns(columns)":`获取ant表头的属性 ;参数->columns : ant的表头`,
getWord({templatePath,params, title, allValues, listConfig, ext});// 下载文档地址 ,前五个必填 templatePath,params, title, allValues, listConfig "getColumnsDataRealize({data, mergeKey, columns, styles, defect, fileName, ext , eliminateStr})":`下载列表合并的数据;参数-> 前三个必填data, mergeKey, columns`,
`, "getColumnsSqlKeyRealize({sqlKey, columns, styles, fileName, ext})":`下载列表表头合并的数据;参数->前两个个必填sqlKey, columns`,
"getWord({templatePath,params, title, allValues, listConfig, ext})":`下载文档地址 ;参数->前五个必填 templatePath,params, title, allValues, listConfig`,
"renderContentAll(value, row, index, key, spanData, cloumnNames) ":`ant表头横向、纵向合并 ;参数->所有必填 value, row, index, key, spanData, cloumnNames 实例:render:(value, row, index)=>{return renderContentAll(value, row, index,"inst_name",spanData,cloumnNames)}`,
"renderContentRow(value, row, index, key, spanData, cloumnNames) ":`ant表头纵向合并 ;参数->所有必填 value, row, index, key, spanData, cloumnNames 实例:render:(value, row, index)=>{return renderContentRow(value, row, index,"inst_name",spanData,cloumnNames)}`,
}
}, },
publicComponent: { publicComponent: {
React, React,
...@@ -59,4 +65,4 @@ export function giveSmartFormGlobalProps({ ...@@ -59,4 +65,4 @@ export function giveSmartFormGlobalProps({
}, },
}; };
return true; return true;
} }
\ No newline at end of file
import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16'; import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16';
import { queryOauthActionPath } from '@/webPublic/one_stop_public/utils/queryConfig'; import { queryOauthActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
import { getToken } from '@/webPublic/one_stop_public/utils/token'; import { getToken } from '@/webPublic/one_stop_public/utils/token';
export { deepCopy} from '@/webPublic/zyd_public/utils/utils';
const apiUrl = queryOauthActionPath();
/** /**
* 公共函数代码 * 公共函数代码
...@@ -11,102 +14,115 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token'; ...@@ -11,102 +14,115 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token';
* 列表获取纵向合并数据 * 列表获取纵向合并数据
* mergeKey : 需要合并的表头key * mergeKey : 需要合并的表头key
* data : 列表数据 * data : 列表数据
* eliminateStr : 需要忽略合并的数据 * eliminateRow : 列需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
* *
* 返回值 * 返回值
* rowSpanData 列合并数据,colSpanData行合并数据 * rowSpanData 列合并数据,colSpanData行合并数据
* */ * */
export function getSpanJson(mergeKey, data, eliminateStr = []) { export function getSpanJson({
return { mergeKey, data, eliminateRow = [], eliminateCol = []
rowSpanData: getRowSpanJson(mergeKey, data, eliminateStr), }) {
colSpanData: getColSpanJson(mergeKey, data, eliminateStr),
}; try {
let dataList = deepCopy(data);
return {
rowSpanData: getRowSpanJson(mergeKey,dataList, eliminateRow),
colSpanData: getColSpanJson(mergeKey, dataList, eliminateCol),
};
} catch (err) {
console.table(err);
}
} }
function getRowSpanJson(cloumnNames, data, eliminateStr = []) { function getRowSpanJson(cloumnNames, data, eliminateStr = []) {
//纵向合并 data = deepCopy(data);
// 获取列的 dataIndex 集合 //纵向合并
var rowSpanJson = {}; // 获取列的 dataIndex 集合
//保存上一个name var rowSpanJson = {};
var beforeNameMap = {}; //保存上一个name
//相同name出现的次数 var beforeNameMap = {};
var countMap = {}; //相同name出现的次数
//该name第一次出现的位置 var countMap = {};
var startIndexMap = {}; //该name第一次出现的位置
for (var idx = 0; idx < data.length; idx++) { var startIndexMap = {};
var dataItem = data[idx]; for (var idx = 0; idx < data.length; idx++) {
for (var idj = 0; idj < cloumnNames.length; idj++) { var dataItem = data[idx];
var keyItem = cloumnNames[idj]; for (var idj = 0; idj < cloumnNames.length; idj++) {
var dataItemValue = dataItem[keyItem]; var keyItem = cloumnNames[idj];
if (idx === 0) { var dataItemValue = dataItem[keyItem];
beforeNameMap[keyItem] = dataItem[keyItem]; if (idx === 0) {
countMap[keyItem] = 1; beforeNameMap[keyItem] = dataItem[keyItem];
startIndexMap[keyItem] = 0; countMap[keyItem] = 1;
rowSpanJson[keyItem] = new Array(data.length); startIndexMap[keyItem] = 0;
rowSpanJson[keyItem][0] = 1; rowSpanJson[keyItem] = new Array(data.length);
continue; rowSpanJson[keyItem][0] = 1;
} continue;
if (dataItemValue === beforeNameMap[keyItem] && eliminateStr.indexOf(dataItemValue) === -1) { }
countMap[keyItem] = countMap[keyItem] + 1; if (dataItemValue === beforeNameMap[keyItem] && eliminateStr.indexOf(dataItemValue) === -1) {
rowSpanJson[keyItem][startIndexMap[keyItem]] = countMap[keyItem]; countMap[keyItem] = countMap[keyItem] + 1;
rowSpanJson[keyItem][idx] = 0; rowSpanJson[keyItem][startIndexMap[keyItem]] = countMap[keyItem];
} else { rowSpanJson[keyItem][idx] = 0;
countMap[keyItem] = 1; } else {
beforeNameMap[keyItem] = dataItemValue; countMap[keyItem] = 1;
startIndexMap[keyItem] = idx; beforeNameMap[keyItem] = dataItemValue;
startIndexMap[keyItem] = idx;
rowSpanJson[keyItem][idx] = 1; rowSpanJson[keyItem][idx] = 1;
} }
} }
} }
return rowSpanJson; return rowSpanJson;
} }
function getColSpanJson(cloumnNames, data, eliminateStr = []) { function getColSpanJson(cloumnNames, data, eliminateStr = []) {
//横向合并 data = deepCopy(data);
var colSpanJson = {}; //横向合并
for (let idx = 0; idx < data.length; idx++) { var colSpanJson = {};
let dataItem = data[idx]; for (let idx = 0; idx < data.length; idx++) {
let colSum = 1; //宽度 let dataItem = data[idx];
let triggerColIndex = null; //记录触发时得位置 let colSum = 1; //宽度
let triggerColSum = 1; //记录触发时得位置 let triggerColIndex = null; //记录触发时得位置
let isCol = false; let triggerColSum = 1; //记录触发时得位置
for (let idj = 0; idj < cloumnNames.length; idj++) { let isCol = false;
let keyItem = cloumnNames[idj]; for (let idj = 0; idj < cloumnNames.length; idj++) {
let dataItemValue = dataItem[keyItem]; let keyItem = cloumnNames[idj];
let dataItemValueNext = idj < cloumnNames.length - 1 ? dataItem[cloumnNames[idj + 1]] : null; let dataItemValue = dataItem[keyItem];
//console.log("dataItemValue",dataItemValue,idj) let dataItemValueNext = idj < cloumnNames.length - 1 ? dataItem[cloumnNames[idj + 1]] : null;
if (idx === 0) { //console.log("dataItemValue",dataItemValue,idj)
colSpanJson[keyItem] = new Array(getRowSpanJson.length); if (idx === 0) {
} colSpanJson[keyItem] = new Array(getRowSpanJson.length);
if ( }
!isCol && if (
dataItemValue === dataItemValueNext && !isCol &&
eliminateStr.indexOf(dataItemValue) === -1 dataItemValue === dataItemValueNext &&
) { eliminateStr.indexOf(dataItemValue) === -1
//触发合并 ) {
triggerColIndex = keyItem; //触发合并
isCol = true; triggerColIndex = keyItem;
} isCol = true;
if (isCol && (dataItemValue !== dataItemValueNext || dataItemValueNext == null)) { }
//合并结束 if (isCol && (dataItemValue !== dataItemValueNext || dataItemValueNext == null)) {
isCol = false; //合并结束
} isCol = false;
if (isCol) { }
//计数 if (isCol) {
triggerColSum++; //计数
} triggerColSum++;
if (!isCol && triggerColIndex !== null) { }
colSpanJson[triggerColIndex][idx] = triggerColSum; if (!isCol && triggerColIndex !== null) {
colSpanJson[keyItem][idx] = 0; colSpanJson[triggerColIndex][idx] = triggerColSum;
triggerColIndex = null; colSpanJson[keyItem][idx] = 0;
} else { triggerColIndex = null;
colSpanJson[keyItem][idx] = colSum; } else if(isCol && triggerColIndex !== null ) {
} colSpanJson[keyItem][idx] = 0;
} } else {
} colSpanJson[keyItem][idx] = colSum;
//console.log("colSpanJson",colSpanJson) }
return colSpanJson; }
}
//console.log("colSpanJson",colSpanJson)
return colSpanJson;
} }
/** /**
...@@ -120,95 +136,97 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { ...@@ -120,95 +136,97 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
* columnsHeight 行数 * columnsHeight 行数
* */ * */
export function getColumns(columns) { export function getColumns(columns) {
const uj = { columns = deepCopy(columns);
t: 1,
v: '序号', const uj = {
s: 'header', t: 1,
}; v: '序号',
let columnsHeight = 0; s: 'header',
getColumnsMaxLevel(columns); //递归行数 };
let columnsKey = []; let columnsHeight = 0;
const columnsList = new Array(columnsHeight).fill([]); getColumnsMaxLevel(columns); //递归行数
let col = 1; let columnsKey = [];
for (var i in columnsList) { const columnsList = new Array(columnsHeight).fill([]);
columnsList[i] = new Array(getColumnsWidth(columns)).fill({}); let col = 1;
} for (var i in columnsList) {
columnsList[i] = new Array(getColumnsWidth(columns)).fill({});
}
function getColumnsData(data = [], res = [], level = 1) { function getColumnsData(data = [], res = [], level = 1) {
for (let item of data) { for (let item of data) {
//item.key = i; //item.key = i;
let isLast = !item.children; let isLast = !item.children;
item.level = level; item.level = level;
item.isLast = isLast; item.isLast = isLast;
item.width = !isLast ? getColumnsWidth(item.children) : 1; item.width = !isLast ? getColumnsWidth(item.children) : 1;
item.col = col; item.col = col;
res.push(item); res.push(item);
columnsList[level - 1][col - 1] = { columnsList[level - 1][col - 1] = {
...uj, ...uj,
v: item.title, v: item.title,
}; };
if (!isLast) { if (!isLast) {
if (Array.isArray(item.children)) { if (Array.isArray(item.children)) {
let x = level + 1; let x = level + 1;
getColumnsData(item.children, res, x); getColumnsData(item.children, res, x);
} }
} else { } else {
col++; col++;
columnsKey.push(item['dataIndex']); columnsKey.push(item['dataIndex']);
} }
} }
return res; return res;
} }
//递归行数 //递归行数
function getColumnsMaxLevel(data = [], level = 1) { function getColumnsMaxLevel(data = [], level = 1) {
for (let item of data) { for (let item of data) {
let isLast = !item.children; let isLast = !item.children;
if (!isLast && Array.isArray(item.children)) { if (!isLast && Array.isArray(item.children)) {
let x = level + 1; let x = level + 1;
if (columnsHeight < x) { if (columnsHeight < x) {
columnsHeight = x; columnsHeight = x;
} }
getColumnsMaxLevel(item.children, x); getColumnsMaxLevel(item.children, x);
} }
} }
return level; return level;
} }
//递归当前数据宽度 //递归当前数据宽度
function getColumnsWidth(data = [], sum = 0) { function getColumnsWidth(data = [], sum = 0) {
for (let item of data) { for (let item of data) {
if (!item.children) { if (!item.children) {
sum++; sum++;
} else { } else {
sum = getColumnsWidth(item.children, sum); sum = getColumnsWidth(item.children, sum);
} }
} }
return sum; return sum;
} }
let columnsHandle = getColumnsData(columns).filter((v, i) => { let columnsHandle = getColumnsData(columns).filter((v, i) => {
return (v.level < columnsHeight && v.isLast) || v.width > 1; return (v.level < columnsHeight && v.isLast) || v.width > 1;
}); });
let columnsMerges = []; let columnsMerges = [];
columnsHandle.forEach((v, i) => { columnsHandle.forEach((v, i) => {
let { isLast, width, col, level } = v; let { isLast, width, col, level } = v;
let nowCol = col - 1; let nowCol = col - 1;
let nowLevel = level - 1; let nowLevel = level - 1;
if (isLast && width === 1) { if (isLast && width === 1) {
//合并表格的 开始行、结束行、开始列、结束列 //合并表格的 开始行、结束行、开始列、结束列
columnsMerges.push([nowLevel, columnsHeight - 1, nowCol, nowCol]); columnsMerges.push([nowLevel, columnsHeight - 1, nowCol, nowCol]);
} }
if (!isLast && width > 1) { if (!isLast && width > 1) {
columnsMerges.push([nowLevel, nowLevel, nowCol, nowCol + width - 1]); columnsMerges.push([nowLevel, nowLevel, nowCol, nowCol + width - 1]);
} }
}); });
return { return {
columnsList, columnsList,
columnsMerges, columnsMerges,
columnsKey, columnsKey,
columnsHeight, columnsHeight,
}; };
} }
/** /**
...@@ -223,67 +241,74 @@ export function getColumns(columns) { ...@@ -223,67 +241,74 @@ export function getColumns(columns) {
* 返回值 * 返回值
* */ * */
export function getColumnsSqlKeyRealize({ export function getColumnsSqlKeyRealize({
sqlKey, sqlKey,
columns, columns,
styles, styles,
fileName = '导出文件', fileName = '导出文件',
ext = 'xlsx', ext = 'xlsx',
}) { }) {
let { columnsList, columnsMerges, columnsKey } = getColumns(columns); columns = deepCopy(columns);
let content = {
sheets: [ let { columnsList, columnsMerges, columnsKey } = getColumns(columns);
{
name: fileName, let content = {
cells: columnsList, sheets: [
merges: columnsMerges, {
sqlKey: sqlKey, //sql编码 name: fileName,
sqlKeyHeader: columnsKey, //sql对应key对应列 cells: columnsList,
}, merges: columnsMerges,
], sqlKey: sqlKey, //sql编码
styles: { sqlKeyHeader: columnsKey, //sql对应key对应列
header: { },
font: { ],
bold: false, styles: {
fontHeightInPoints: 12, header: {
}, font: {
alignment: 'CENTER', bold: false,
borderLeft: 'THIN', fontHeightInPoints: 12,
borderTop: 'THIN', },
borderBottom: 'THIN', alignment: 'CENTER',
borderRight: 'THIN', borderLeft: 'THIN',
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED borderTop: 'THIN',
wrapText: true, borderBottom: 'THIN',
rowHeights: 20, borderRight: 'THIN',
colWidths: 200, verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED
}, wrapText: true,
head: { rowHeights: 20,
font: { colWidths: 250,
bold: true, },
}, head: {
alignment: 'CENTER', font: {
}, bold: true,
}, },
}; alignment: 'CENTER',
if (styles) { },
content.styles = styles; },
} };
let getFileData = giveFilePostDataInfoForTrue( if (styles) {
{ content.styles = styles;
content: JSON.stringify(content), }
title: fileName, try {
}, let getFileData = giveFilePostDataInfoForTrue(
`${queryOauthActionPath() + '/DataObjApi/exportCustom'}`, {
); content: JSON.stringify(content),
let token = getToken(); title: fileName,
downloadFile( },
getFileData.url, `${apiUrl + '/DataObjApi/exportCustom'}`,
{ );
...getFileData.datas, let token = getToken();
token: token, downloadFile(
}, getFileData.url,
fileName, {
ext, ...getFileData.datas,
); token: token,
},
fileName,
ext,
);
} catch (err) {
console.table(err);
}
} }
/** /**
...@@ -295,111 +320,173 @@ export function getColumnsSqlKeyRealize({ ...@@ -295,111 +320,173 @@ export function getColumnsSqlKeyRealize({
* fileName : 导出文件名 * fileName : 导出文件名
* ext : 导出后缀 目前xecl、dbf * ext : 导出后缀 目前xecl、dbf
* url : 接口地址 * url : 接口地址
* eliminateStr : 忽略合并的值 * eliminateRow : 列需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
* 返回值 * 返回值
* */ * */
export function getColumnsDataRealize({ export function getColumnsDataRealize({
data = [], data = [],
mergeKey = [], mergeKey = [],
columns, columns,
styles, styles,
defect = null, defect = null,
fileName = '导出文件', fileName = '导出文件',
ext = 'xlsx', ext = 'xlsx',
eliminateStr = [], eliminateRow = [],
eliminateCol = [],
}) { }) {
let { columnsList, columnsMerges, columnsKey, columnsHeight } = getColumns(columns); columns = deepCopy(columns);
let { colSpanData, rowSpanData } = getSpanJson(mergeKey, data, eliminateStr); data = deepCopy(data);
// 处理数据 let { columnsList, columnsMerges, columnsKey, columnsHeight } = getColumns(columns);
let bodyData = []; let { colSpanData, rowSpanData } = getSpanJson({ mergeKey, data, eliminateRow, eliminateCol });
const uj = { // 处理数据
t: 1, let bodyData = [];
v: '序号', let dataMerges = [];
s: 'header', const uj = {
}; t: 1,
data.forEach((dv, di) => { v: '序号',
let nowArroy = new Array(columnsKey.length).fill({}); s: 'header',
columnsKey.forEach((av, ai) => { };
nowArroy[ai] = { try {
...uj, data.forEach((dv, di) => {
v: av in dv ? dv[av].toString() : defect || '', let nowArroy = new Array(columnsKey.length).fill({});
}; columnsKey.forEach((av, ai) => {
}); nowArroy[ai] = {
bodyData.push(nowArroy); ...uj,
}); v: av in dv && dv[av] != null ? dv[av].toString() : defect || '',
// 处理合并数据 };
let dataMerges = []; });
mergeKey.forEach((mv, mi) => { bodyData.push(nowArroy);
rowSpanData[mv].forEach((cv, ci) => { });
if (cv > 1) { // 处理合并数据
//合并表格的 开始行、结束行、开始列、结束列 mergeKey.forEach((mv, mi) => {
let rowIndex = columnsKey.indexOf(mv); rowSpanData[mv].forEach((cv, ci) => {
dataMerges.push([columnsHeight + ci, columnsHeight + ci + cv - 1, rowIndex, rowIndex]); if (cv > 1) {
} //合并表格的 开始行、结束行、开始列、结束列
}); let rowIndex = columnsKey.indexOf(mv);
colSpanData[mv].forEach((cv, ci) => { dataMerges.push([columnsHeight + ci, columnsHeight + ci + cv - 1, rowIndex, rowIndex]);
if (cv > 1) { }
//合并表格的 开始行、结束行、开始列、结束列 });
let rowIndex = columnsKey.indexOf(mv); colSpanData[mv].forEach((cv, ci) => {
dataMerges.push([columnsHeight + ci, columnsHeight + ci, rowIndex, rowIndex + cv - 1]); 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: [
{
name: fileName,
cells: [...columnsList, ...bodyData],
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',
},
},
};
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(err);
}
}
// ant列表组件合并表格 render属性,合并纵向、横向。
export function renderContentAll(value, row, index, key, spanData, cloumnNames = []) {
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: {
rowSpan: rowSpan,
colSpan: colSpan
}
};
return obj;
}
let content = { // ant列表组件合并表格 render属性,合并纵向。 meanwhileKey :key 是本身字段key,value 是同步的字段key
sheets: [ export function renderContentRow(value, row, index, key, spanData, cloumnNames = [], meanwhileKey = {}) {
{ let colSpan, rowSpan = null;
name: fileName, try {
cells: [...columnsList, ...bodyData], if (cloumnNames.indexOf(key) !== -1) {
merges: [...columnsMerges, ...dataMerges], rowSpan = spanData.rowSpanData[key][index];// 纵向合并
}, } else {
], if (key in meanwhileKey && meanwhileKey[key]) {
styles: { let meanwhileKeyValue = meanwhileKey[key];
header: { rowSpan = spanData.rowSpanData[meanwhileKeyValue][index];// 同步字段 的纵向合并
font: { } else {
bold: false, rowSpan = 1;
fontHeightInPoints: 12, }
}, }
alignment: 'CENTER', } catch (err) {
borderLeft: 'THIN', console.table(err);
borderTop: 'THIN', }
borderBottom: 'THIN', const obj = {
borderRight: 'THIN', children: value,
verticalAlignment: 'CENTER', //TOP、CENTER、BOTTOM、JUSTIFY、DISTRIBUTED props: {
wrapText: true, rowSpan: rowSpan,
rowHeights: 20, colSpan: 1
colWidths: 200, }
}, };
head: { return obj;
font: {
bold: true,
},
alignment: 'CENTER',
},
},
};
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,
);
} }
/** /**
* 表头和数据导出(合并表格) * 表头和数据导出(合并表格)
* templatePath : word文档模板地址 * templatePath : word文档模板地址
...@@ -407,125 +494,129 @@ export function getColumnsDataRealize({ ...@@ -407,125 +494,129 @@ export function getColumnsDataRealize({
* title : 导出文件名 * title : 导出文件名
* allValues : sql参数 * allValues : sql参数
* listConfig : 导出列表配置 * listConfig : 导出列表配置
* ext : 导出后缀 目前xecl、dbf * ext : 导出后缀 目前xecl、dbf,docx,pdf
* 返回值 * 返回值
* */ * */
export function getWord({ export function getWord({
templatePath, templatePath,
params, params,
title, title,
allValues = {}, allValues = {},
listConfig = {}, listConfig = {},
ext = 'docx', ext = 'docx',
}) { }) {
//可更新的 try {
let getFileData = giveFilePostDataInfoForTrue( let getFileData = giveFilePostDataInfoForTrue(
{ {
templatePath: templatePath, templatePath: templatePath,
params: JSON.stringify({ params: JSON.stringify({
...listConfig, ...listConfig,
...setObjectKey(params), ...setObjectKey(params),
}), }),
title: `${title}.${ext}`, title: `${title}.${ext}`,
allValues: JSON.stringify({ ...allValues }), allValues: JSON.stringify({ ...allValues }),
}, },
`${queryOauthActionPath()}` + `/DataColumnApi/exportWord`, apiUrl + `/DataColumnApi/exportWord`,
); );
let token = getToken(); let token = getToken();
downloadFile( downloadFile(
getFileData.url, getFileData.url,
{ {
...getFileData.datas, ...getFileData.datas,
token: token, token: token,
}, },
title, title,
ext, ext,
); );
} catch (err) {
console.table(err);
}
//可更新的
function setObjectKey(data) { function setObjectKey(data) {
return ( return (
Object.keys(data) Object.keys(data)
//.filter((key) => data[key] !== null && data[key] !== undefined) //.filter((key) => data[key] !== null && data[key] !== undefined)
.reduce( .reduce(
(acc, key) => ({ (acc, key) => ({
...acc, ...acc,
['${' + key + '}']: data[key] === null ? '' : data[key], ['${' + key + '}']: data[key] === null ? '' : data[key],
}), }),
{}, {},
) )
); );
} }
} }
// 下载附件FormdataWrapper // 下载附件FormdataWrapper
function isObject(value) { function isObject(value) {
return value === Object(value); return value === Object(value);
} }
function isArray(value) { function isArray(value) {
return Array.isArray(value); return Array.isArray(value);
} }
function isFile(value) { function isFile(value) {
return value instanceof File; return value instanceof File;
} }
function makeArrayKey(key) { function makeArrayKey(key) {
return key; return key;
} }
function FormdataWrapper(obj, fd, pre) { function FormdataWrapper(obj, fd, pre) {
fd = fd || new FormData(); fd = fd || new FormData();
Object.keys(obj).forEach(function(prop) { Object.keys(obj).forEach(function (prop) {
var key = pre ? pre + '[' + prop + ']' : prop; var key = pre ? pre + '[' + prop + ']' : prop;
if (isObject(obj[prop]) && !isArray(obj[prop]) && !isFile(obj[prop])) { if (isObject(obj[prop]) && !isArray(obj[prop]) && !isFile(obj[prop])) {
FormdataWrapper(obj[prop], fd, key); FormdataWrapper(obj[prop], fd, key);
} else if (isArray(obj[prop])) { } else if (isArray(obj[prop])) {
obj[prop].forEach(function(value) { obj[prop].forEach(function (value) {
var arrayKey = makeArrayKey(key); var arrayKey = makeArrayKey(key);
if (isObject(value) && !isFile(value)) { if (isObject(value) && !isFile(value)) {
FormdataWrapper(value, fd, arrayKey); FormdataWrapper(value, fd, arrayKey);
} else { } else {
fd.append(arrayKey, value); fd.append(arrayKey, value);
} }
}); });
} else { } else {
if (obj[prop] != null) fd.append(key, obj[prop]); if (obj[prop] != null) fd.append(key, obj[prop]);
} }
}); });
return fd; return fd;
} }
function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') { function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
// console.log("downloadFile",url); // console.log("downloadFile",url);
fetch(url, { fetch(url, {
method: 'POST', method: 'POST',
body: FormdataWrapper(params), body: FormdataWrapper(params),
}) })
.then((res) => { .then((res) => {
if (res.status + '' !== '200') { if (res.status + '' !== '200') {
return res.json(); return res.json();
} else { } else {
return res.blob(); return res.blob();
} }
}) })
.then((data) => { .then((data) => {
if (data instanceof Blob) { if (data instanceof Blob) {
let a = document.createElement('a'); let a = document.createElement('a');
let url = window.URL.createObjectURL(data); let url = window.URL.createObjectURL(data);
let filename = fileName + '.' + ext; let filename = fileName + '.' + ext;
a.href = url; a.href = url;
a.download = filename; a.download = filename;
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
a = null; a = null;
} else { } else {
} }
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}) })
.finally(() => { .finally(() => {
return true; return true;
}); });
} }
...@@ -47,6 +47,7 @@ export default function RangePickerDiy(props){ ...@@ -47,6 +47,7 @@ export default function RangePickerDiy(props){
const [bindValue, setBindValue] = useState([undefined, undefined]); const [bindValue, setBindValue] = useState([undefined, undefined]);
useEffect(() => { useEffect(() => {
// console.log('RangePickerDiy组件Value', value);
if(!value || !Array.isArray(value) || value.length !==2){ if(!value || !Array.isArray(value) || value.length !==2){
setBindValue([undefined, undefined]); setBindValue([undefined, undefined]);
...@@ -56,7 +57,7 @@ export default function RangePickerDiy(props){ ...@@ -56,7 +57,7 @@ export default function RangePickerDiy(props){
bindValue[i] = moment(value[i]); bindValue[i] = moment(value[i]);
}else if(!moment.isMoment(value[i])){ }else if(!moment.isMoment(value[i])){
bindValue[i] = undefined; bindValue[i] = undefined;
console.log('RangePickerDiy组件没有获取到正确的值', value); // console.log('RangePickerDiy组件没有获取到正确的值', value);
}else{ }else{
bindValue[i] = value[i]; bindValue[i] = value[i];
} }
......
...@@ -85,6 +85,7 @@ export function changeFromDraftState2(editorState) { ...@@ -85,6 +85,7 @@ export function changeFromDraftState2(editorState) {
} }
export function preHandle(values) { export function preHandle(values) {
// console.trace('123');
for (var key in values) { for (var key in values) {
if (!values[key]) continue; if (!values[key]) continue;
if (key.indexOf('$') > -1) { if (key.indexOf('$') > -1) {
...@@ -118,13 +119,14 @@ export function preHandle(values) { ...@@ -118,13 +119,14 @@ export function preHandle(values) {
j.split('$').map((g,index) => { j.split('$').map((g,index) => {
if(moment.isMoment(childObj[j][index])){ if(moment.isMoment(childObj[j][index])){
childObj[g] = childObj[j][index].valueOf(); childObj[g] = childObj[j][index].valueOf();
childObj[j][index] = childObj[j][index].valueOf(); // childObj[j][index] = childObj[j][index].valueOf();
} }
}); });
if(j === 'LckrMFujFgw$LckrXpIoQdc'){ if(j === 'LckrMFujFgw$LckrXpIoQdc'){
console.log(values[key][k][j], key, k, j); // console.log(values[key][k]['LckrMFujFgw'], key, k, j);
// console.log(values[key][k]['LckrXpIoQdc'], key, k, j);
} }
// delete childObj[j]; delete childObj[j];
// 我写的代码 // 我写的代码
// 欢哥写的代码. // 欢哥写的代码.
...@@ -167,6 +169,9 @@ export function deepCopy(obj, parent = null) { ...@@ -167,6 +169,9 @@ export function deepCopy(obj, parent = null) {
if (React.isValidElement(obj)) { if (React.isValidElement(obj)) {
return React.cloneElement(obj); return React.cloneElement(obj);
} }
// if(moment.isMoment(obj)){
// return moment().clone)
// }
if (['boolean', 'string', 'number'].indexOf(typeof obj) > -1 || !obj) { if (['boolean', 'string', 'number'].indexOf(typeof obj) > -1 || !obj) {
return obj; return obj;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论