Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
23174415
提交
23174415
authored
2月 09, 2023
作者:
姚鑫国
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
getColumnsDataRealize
优化 方法,新增映射合并 新增合并主键
上级
62236816
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
65 行增加
和
23 行删除
+65
-23
globalFunction.js
one_stop_public/Table/globalFunction.js
+65
-23
没有找到文件。
one_stop_public/Table/globalFunction.js
浏览文件 @
23174415
...
...
@@ -54,16 +54,18 @@ const uj = {
* rowSpanData 列合并数据,colSpanData行合并数据
* */
export
function
getSpanJson
({
mergeKey
,
mergeKey
=
[]
,
data
,
eliminateRow
=
[],
eliminateCol
=
[]
eliminateCol
=
[],
mergePrimaryRow
,
mergeMappingRow
=
{}
// 某一列的合并数据 复制 到任意其他列
})
{
const
dataList
=
deepCopy
(
data
);
let
rowSpanData
,
colSpanData
=
null
;
try
{
rowSpanData
=
getRowSpanJson
(
mergeKey
,
dataList
,
eliminateRow
);
rowSpanData
=
getRowSpanJson
(
mergeKey
,
dataList
,
eliminateRow
,
mergePrimaryRow
);
}
catch
(
err
)
{
console
.
table
(
"rowSpanData"
,
err
);
}
...
...
@@ -72,13 +74,24 @@ export function getSpanJson({
}
catch
(
err
)
{
console
.
table
(
"colSpanData"
,
err
);
}
try
{
const
newMergeMappingRow
=
Object
.
keys
(
mergeMappingRow
).
filter
(
item1
=>
mergeKey
.
some
(
item2
=>
item2
===
item1
));
newMergeMappingRow
.
map
((
item
)
=>
{
const
mappingList
=
mergeMappingRow
[
item
].
filter
(
item1
=>
!
mergeKey
.
some
(
item2
=>
item2
===
item1
));
mappingList
.
map
((
mItem
)
=>
{
rowSpanData
[
mItem
]
=
rowSpanData
[
item
];
});
});
}
catch
(
e
)
{
console
.
table
(
"mergeMappingRow"
,
e
);
}
return
{
rowSpanData
,
colSpanData
,
};
}
function
getRowSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
function
getRowSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[]
,
mergePrimaryRow
)
{
data
=
deepCopy
(
data
);
//纵向合并
// 获取列的 dataIndex 集合
...
...
@@ -89,20 +102,32 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) {
var
countMap
=
{};
//该name第一次出现的位置
var
startIndexMap
=
{};
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 是否主键模式
var
isPrimary
=
false
;
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 循环数据
var
dataItem
=
data
[
idx
];
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
var
dataItemRowValue
;
var
dataItemPreviousRowValue
;
if
(
mergePrimaryRow
)
{
isPrimary
=
true
;
//开启主键模式
dataItemRowValue
=
dataItem
[
mergePrimaryRow
];
dataItemPreviousRowValue
=
data
[
idx
-
1
>
0
?
idx
-
1
:
0
][
mergePrimaryRow
];
}
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
// 循环表头
var
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
beforeNameMap
[
keyItem
]
=
dataItem
[
keyItem
]
;
beforeNameMap
[
keyItem
]
=
dataItem
Value
;
countMap
[
keyItem
]
=
1
;
startIndexMap
[
keyItem
]
=
0
;
rowSpanJson
[
keyItem
]
=
new
Array
(
data
.
length
);
rowSpanJson
[
keyItem
][
0
]
=
1
;
continue
;
}
if
(
dataItemValue
===
beforeNameMap
[
keyItem
]
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
)
{
if
(
(
!
isPrimary
?
(
dataItemValue
===
beforeNameMap
[
keyItem
])
:
(
dataItemRowValue
+
dataItemValue
===
dataItemPreviousRowValue
+
beforeNameMap
[
keyItem
]))
// 与上一个值一致时
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
// 排除特定的值合并
)
{
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
rowSpanJson
[
keyItem
][
idx
]
=
0
;
...
...
@@ -110,7 +135,6 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) {
countMap
[
keyItem
]
=
1
;
beforeNameMap
[
keyItem
]
=
dataItemValue
;
startIndexMap
[
keyItem
]
=
idx
;
rowSpanJson
[
keyItem
][
idx
]
=
1
;
}
}
...
...
@@ -132,7 +156,6 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
let
keyItem
=
cloumnNames
[
idj
];
let
dataItemValue
=
dataItem
[
keyItem
];
let
dataItemValueNext
=
idj
<
cloumnNames
.
length
-
1
?
dataItem
[
cloumnNames
[
idj
+
1
]]
:
null
;
//console.log("dataItemValue",dataItemValue,idj)
if
(
idx
===
0
)
{
colSpanJson
[
keyItem
]
=
new
Array
(
data
.
length
);
}
...
...
@@ -164,7 +187,6 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
}
}
}
//console.log("colSpanJson",colSpanJson)
return
colSpanJson
;
}
...
...
@@ -214,7 +236,7 @@ export function getColumns(columns) {
}
return
res
;
}
catch
(
e
)
{
console
.
table
(
"getColumnsData"
,
e
);
console
.
table
(
"getColumnsData
s
"
,
e
);
return
[];
}
}
...
...
@@ -436,6 +458,8 @@ export function getColumnsDataRealize({
ext
=
'xlsx'
,
eliminateRow
=
[],
eliminateCol
=
[],
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
let
content
=
getColumnsData
({
data
,
...
...
@@ -447,6 +471,8 @@ export function getColumnsDataRealize({
ext
,
eliminateRow
,
eliminateCol
,
mergeMappingRow
,
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
});
if
(
styles
)
{
content
.
styles
=
styles
;
...
...
@@ -561,7 +587,9 @@ export function getCustomDataRealize({
* ext : 导出后缀 目前xecl、dbf
* url : 接口地址
* eliminateRow : 列需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
* eliminateCol : 行需要忽略合并的数据
* mergeMappingRow : *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面,value不可以在mergeKey里。
* mergePrimary : 所有合并都会在当前mergePrimary 的范围下合并
*
*/
export
function
getColumnsData
({
...
...
@@ -575,6 +603,8 @@ export function getColumnsData({
eliminateRow
=
[],
eliminateCol
=
[],
docxSheet
=
{},
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
columns
=
deepCopy
(
columns
);
data
=
deepCopy
(
data
);
...
...
@@ -591,7 +621,9 @@ export function getColumnsData({
mergeKey
,
data
,
eliminateRow
,
eliminateCol
eliminateCol
,
mergeMappingRow
,
mergePrimaryRow
});
// 处理数据
let
bodyData
=
[];
...
...
@@ -608,7 +640,17 @@ export function getColumnsData({
bodyData
.
push
(
nowArroy
);
});
// 处理合并数据
mergeKey
.
forEach
((
mv
,
mi
)
=>
{
let
newMergeKey
=
mergeKey
;
try
{
const
newMergeMappingRow
=
Object
.
keys
(
mergeMappingRow
).
filter
(
item1
=>
mergeKey
.
some
(
item2
=>
item2
===
item1
));
newMergeMappingRow
.
map
((
item
)
=>
{
const
mappingList
=
mergeMappingRow
[
item
].
filter
(
item1
=>
!
mergeKey
.
some
(
item2
=>
item2
===
item1
));
newMergeKey
=
[...
newMergeKey
,
...
mappingList
];
});
}
catch
(
e
)
{
console
.
table
(
"newMergeKey"
,
e
);
}
Object
.
keys
(
rowSpanData
).
forEach
((
mv
)
=>
{
rowSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
...
...
@@ -616,6 +658,8 @@ export function getColumnsData({
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
+
cv
-
1
,
rowIndex
,
rowIndex
]);
}
});
})
Object
.
keys
(
colSpanData
).
forEach
((
mv
)
=>
{
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
...
...
@@ -623,7 +667,7 @@ export function getColumnsData({
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
});
})
;
})
}
catch
(
err
)
{
console
.
table
(
"getColumnsData"
,
err
);
}
...
...
@@ -724,7 +768,7 @@ export function getCustomData({
});
});
}
catch
(
err
)
{
console
.
table
(
"getC
olumns
Data"
,
err
);
console
.
table
(
"getC
ustom
Data"
,
err
);
}
const
columnsDataCells
=
[...
columnsList
,
...
bodyData
];
...
...
@@ -732,7 +776,7 @@ export function getCustomData({
let
newBottomMerges
=
[];
if
(
bottomList
&&
bottomList
.
length
>
0
)
{
// 新增底部数据
if
(
columnsKey
.
length
!=
bottomList
[
0
].
length
)
{
console
.
log
(
"bottomList数据列数和表头列数不一致"
);
console
.
table
(
"bottomList数据列数和表头列数不一致"
);
return
}
newBottomMerges
=
bottomMerges
.
map
((
v
,
i
)
=>
{
...
...
@@ -1064,7 +1108,7 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
return
null
;
}
}
catch
(
error
)
{
console
.
log
(
"upObjKey"
,
error
);
console
.
table
(
"upObjKey"
,
error
);
return
undefined
;
}
}
...
...
@@ -1157,7 +1201,6 @@ function FormdataWrapper(obj, fd, pre) {
}
export
async
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
// console.log("downloadFile",url);
const
{
transformApi
,
headersApi
}
=
await
getTransformApi
(
url
);
let
headers
=
{
Authorization
:
`bearer
${
localStorage
.
getItem
(
'antd-pro-token-onestop'
)}
`
,
...
...
@@ -1192,7 +1235,7 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
table
(
err
);
})
.
finally
(()
=>
{
return
true
;
...
...
@@ -1201,7 +1244,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
export
async
function
downloadFileAndShowModal
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
// console.log("downloadFile",url);
const
{
transformApi
,
headersApi
}
=
await
getTransformApi
(
url
);
let
headers
=
{
Authorization
:
`bearer
${
localStorage
.
getItem
(
'antd-pro-token-onestop'
)}
`
,
...
...
@@ -1256,7 +1298,7 @@ export async function downloadFileAndShowModal(url, params, fileName = '导出
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
table
(
err
);
})
.
finally
(()
=>
{
return
true
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论