Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
bfa4224f
提交
bfa4224f
authored
6月 01, 2022
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加公共函数
上级
0751573a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
258 行增加
和
152 行删除
+258
-152
giveSmartFormGlobalProps.js
one_stop_public/Table/giveSmartFormGlobalProps.js
+14
-9
globalFunction.js
one_stop_public/Table/globalFunction.js
+244
-143
没有找到文件。
one_stop_public/Table/giveSmartFormGlobalProps.js
浏览文件 @
bfa4224f
import
React
from
'react'
;
import
React
from
'react'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
{
Modal
,
message
,
notification
,
Tooltip
,
Spin
,
Popover
,
Popconfirm
}
from
'antd'
;
import
{
Modal
,
message
,
notification
,
Tooltip
,
Spin
,
Popover
,
Popconfirm
}
from
'antd'
;
import
{
giveFilePostDataInfoForTrue
}
from
'@/webPublic/one_stop_public/Base16'
;
import
{
giveFilePostDataInfoForTrue
}
from
'@/webPublic/one_stop_public/Base16'
;
import
{
getSpanJson
,
getColumns
,
getColumnsDataRealize
,
getColumnsSqlKeyRealize
,
getWord
}
from
'@/webPublic/one_stop_public/Table'
;
import
{
getSpanJson
,
getColumns
,
getColumnsDataRealize
,
getColumnsSqlKeyRealize
,
getWord
,
}
from
'./globalFunction'
;
export
function
giveSmartFormGlobalProps
({
export
function
giveSmartFormGlobalProps
({
fromStart
=
false
,
fromStart
=
false
,
...
@@ -15,8 +20,7 @@ export function giveSmartFormGlobalProps({
...
@@ -15,8 +20,7 @@ export function giveSmartFormGlobalProps({
data
=
{},
data
=
{},
nextUsers
=
{},
//
nextUsers
=
{},
//
calculateFlowData
=
[],
// 移动端使用 用于分块块 禅道 23933 移动端全表单后审核步骤的显示问题优化
calculateFlowData
=
[],
// 移动端使用 用于分块块 禅道 23933 移动端全表单后审核步骤的显示问题优化
})
{
})
{
window
.
smartFormGlobalProps
=
{
window
.
smartFormGlobalProps
=
{
fromStart
,
fromStart
,
hasSingle
,
hasSingle
,
...
@@ -33,12 +37,13 @@ export function giveSmartFormGlobalProps({
...
@@ -33,12 +37,13 @@ export function giveSmartFormGlobalProps({
getColumnsDataRealize
,
getColumnsDataRealize
,
getColumnsSqlKeyRealize
,
getColumnsSqlKeyRealize
,
getWord
,
getWord
,
remark
:
`'giveFilePostDataInfoForTrue(params, url); //将接口参数 二进制文件化 并返回新的接口地址与参数';
remark
:
`
giveFilePostDataInfoForTrue(params, url); //将接口参数 二进制文件化 并返回新的接口地址与参数';
getSpanJson(mergeKey, data, eliminateStr); //列表获取纵向合并数据 mergeKey : 需要合并的表头key data : 列表数据 eliminateStr : 需要忽略合并的数据
getSpanJson(mergeKey, data, eliminateStr); //列表获取纵向合并数据 mergeKey : 需要合并的表头key data : 列表数据 eliminateStr : 需要忽略合并的数据
getColumns(columns); //获取ant表头的属性 columns : ant的表头
getColumns(columns); //获取ant表头的属性 columns : ant的表头
getColumnsDataRealize(
data, mergeKey, columns, styles, defect, fileName, ext , url, eliminateStr
); // 下载列表合并的数据,前三个必填data, mergeKey, columns
getColumnsDataRealize(
{data, mergeKey, columns, styles, defect, fileName, ext , eliminateStr}
); // 下载列表合并的数据,前三个必填data, mergeKey, columns
getColumnsSqlKeyRealize(
sqlKey, columns, styles, fileName, ext, url
); // 下载列表表头合并的数据,前两个个必填sqlKey, columns
getColumnsSqlKeyRealize(
{sqlKey, columns, styles, fileName, ext}
); // 下载列表表头合并的数据,前两个个必填sqlKey, columns
getWord(
templatePath,params, title, allValues, listConfig, ext
);// 下载文档地址 ,前五个必填 templatePath,params, title, allValues, listConfig
getWord(
{templatePath,params, title, allValues, listConfig, ext}
);// 下载文档地址 ,前五个必填 templatePath,params, title, allValues, listConfig
`
,
`
,
},
},
publicComponent
:
{
publicComponent
:
{
...
...
one_stop_public/Table/globalFunction.js
浏览文件 @
bfa4224f
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
{
getToken
}
from
'@/webPublic/one_stop_public/utils/token'
;
/**
/**
* 公共函数代码
* 公共函数代码
...
@@ -14,14 +16,15 @@ import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16'
...
@@ -14,14 +16,15 @@ import { giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16'
* 返回值
* 返回值
* rowSpanData 列合并数据,colSpanData行合并数据
* rowSpanData 列合并数据,colSpanData行合并数据
* */
* */
export
default
function
getSpanJson
(
mergeKey
,
data
,
eliminateStr
=
[])
{
export
function
getSpanJson
(
mergeKey
,
data
,
eliminateStr
=
[])
{
return
{
return
{
rowSpanData
:
getRowSpanJson
(
mergeKey
,
data
,
eliminateStr
),
rowSpanData
:
getRowSpanJson
(
mergeKey
,
data
,
eliminateStr
),
colSpanData
:
getColSpanJson
(
mergeKey
,
data
,
eliminateStr
)
colSpanData
:
getColSpanJson
(
mergeKey
,
data
,
eliminateStr
),
}
};
}
}
function
getRowSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//纵向合并
function
getRowSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//纵向合并
// 获取列的 dataIndex 集合
// 获取列的 dataIndex 集合
var
rowSpanJson
=
{};
var
rowSpanJson
=
{};
//保存上一个name
//保存上一个name
...
@@ -33,7 +36,6 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) { //纵向合并
...
@@ -33,7 +36,6 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) { //纵向合并
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
var
dataItem
=
data
[
idx
];
var
dataItem
=
data
[
idx
];
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
var
keyItem
=
cloumnNames
[
idj
];
var
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
if
(
idx
===
0
)
{
...
@@ -60,13 +62,14 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) { //纵向合并
...
@@ -60,13 +62,14 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = []) { //纵向合并
return
rowSpanJson
;
return
rowSpanJson
;
}
}
function
getColSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//横向合并
function
getColSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//横向合并
var
colSpanJson
=
{};
var
colSpanJson
=
{};
for
(
let
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
for
(
let
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
let
dataItem
=
data
[
idx
];
let
dataItem
=
data
[
idx
];
let
colSum
=
1
;
//宽度
let
colSum
=
1
;
//宽度
let
triggerColIndex
=
null
;
//记录触发时得位置
let
triggerColIndex
=
null
;
//记录触发时得位置
let
triggerColSum
=
1
;
//记录触发时得位置
let
triggerColSum
=
1
;
//记录触发时得位置
let
isCol
=
false
;
let
isCol
=
false
;
for
(
let
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
for
(
let
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
let
keyItem
=
cloumnNames
[
idj
];
let
keyItem
=
cloumnNames
[
idj
];
...
@@ -76,24 +79,30 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { //横向合并
...
@@ -76,24 +79,30 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { //横向合并
if
(
idx
===
0
)
{
if
(
idx
===
0
)
{
colSpanJson
[
keyItem
]
=
new
Array
(
getRowSpanJson
.
length
);
colSpanJson
[
keyItem
]
=
new
Array
(
getRowSpanJson
.
length
);
}
}
if
(
!
isCol
&&
dataItemValue
===
dataItemValueNext
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
)
{
//触发合并
if
(
!
isCol
&&
dataItemValue
===
dataItemValueNext
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
)
{
//触发合并
triggerColIndex
=
keyItem
;
triggerColIndex
=
keyItem
;
isCol
=
true
;
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
)
{
if
(
!
isCol
&&
triggerColIndex
!==
null
)
{
colSpanJson
[
triggerColIndex
][
idx
]
=
triggerColSum
colSpanJson
[
triggerColIndex
][
idx
]
=
triggerColSum
;
colSpanJson
[
keyItem
][
idx
]
=
0
;
colSpanJson
[
keyItem
][
idx
]
=
0
;
triggerColIndex
=
null
;
triggerColIndex
=
null
;
}
else
{
}
else
{
colSpanJson
[
keyItem
][
idx
]
=
colSum
;
colSpanJson
[
keyItem
][
idx
]
=
colSum
;
};
}
}
}
}
}
//console.log("colSpanJson",colSpanJson)
//console.log("colSpanJson",colSpanJson)
...
@@ -110,16 +119,21 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { //横向合并
...
@@ -110,16 +119,21 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) { //横向合并
* columnsKey key对应的列
* columnsKey key对应的列
* columnsHeight 行数
* columnsHeight 行数
* */
* */
export
default
function
getColumns
(
columns
)
{
export
function
getColumns
(
columns
)
{
const
uj
=
{
"t"
:
1
,
"v"
:
"序号"
,
s
:
"header"
};
const
uj
=
{
t
:
1
,
v
:
'序号'
,
s
:
'header'
,
};
let
columnsHeight
=
0
;
let
columnsHeight
=
0
;
getColumnsMaxLevel
(
columns
);
//递归行数
getColumnsMaxLevel
(
columns
);
//递归行数
let
columnsKey
=
[];
let
columnsKey
=
[];
const
columnsList
=
new
Array
(
columnsHeight
).
fill
([]);
const
columnsList
=
new
Array
(
columnsHeight
).
fill
([]);
let
col
=
1
;
let
col
=
1
;
for
(
var
i
in
columnsList
)
{
for
(
var
i
in
columnsList
)
{
columnsList
[
i
]
=
new
Array
(
getColumnsWidth
(
columns
)).
fill
({});
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;
...
@@ -129,7 +143,10 @@ export default function getColumns(columns) {
...
@@ -129,7 +143,10 @@ export default function getColumns(columns) {
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
]
=
{
...
uj
,
v
:
item
.
title
};
columnsList
[
level
-
1
][
col
-
1
]
=
{
...
uj
,
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
;
...
@@ -137,11 +154,12 @@ export default function getColumns(columns) {
...
@@ -137,11 +154,12 @@ export default function getColumns(columns) {
}
}
}
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
)
{
...
@@ -155,7 +173,8 @@ export default function getColumns(columns) {
...
@@ -155,7 +173,8 @@ export default function getColumns(columns) {
}
}
}
}
return
level
;
return
level
;
};
}
//递归当前数据宽度
//递归当前数据宽度
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
for
(
let
item
of
data
)
{
for
(
let
item
of
data
)
{
...
@@ -166,27 +185,37 @@ export default function getColumns(columns) {
...
@@ -166,27 +185,37 @@ export default function getColumns(columns) {
}
}
}
}
return
sum
;
return
sum
;
};
}
let
columnsHandle
=
getColumnsData
(
columns
).
filter
((
v
,
i
)
=>
{
return
(
v
.
level
<
columnsHeight
&&
v
.
isLast
)
||
v
.
width
>
1
let
columnsHandle
=
getColumnsData
(
columns
)
.
filter
((
v
,
i
)
=>
{
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
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
};
return
{
};
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
,
};
}
/**
/**
* 表头和sql数据导出(表头合并表格,数据不合并表格)
* 表头和sql数据导出(表头合并表格,数据不合并表格)
...
@@ -199,41 +228,51 @@ export default function getColumns(columns) {
...
@@ -199,41 +228,51 @@ export default function getColumns(columns) {
*
*
* 返回值
* 返回值
* */
* */
export
default
function
getColumnsSqlKeyRealize
(
sqlKey
,
columns
,
styles
,
fileName
=
"导出文件"
,
ext
=
'xlsx'
,
url
=
`/DataObjApi/exportCustom`
)
{
export
function
getColumnsSqlKeyRealize
({
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
sqlKey
,
columns
,
styles
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
})
{
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
content
=
{
let
content
=
{
"sheets"
:
[
sheets
:
[
{
{
"name"
:
fileName
,
name
:
fileName
,
"cells"
:
columnsList
,
cells
:
columnsList
,
"merges"
:
columnsMerges
,
merges
:
columnsMerges
,
"sqlKey"
:
sqlKey
,
//sql编码
sqlKey
:
sqlKey
,
//sql编码
"sqlKeyHeader"
:
columnsKey
//sql对应key对应列
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
}
},
],
],
"styles"
:
{
styles
:
{
"header"
:
{
header
:
{
"font"
:
{
font
:
{
"bold"
:
false
,
bold
:
false
,
"fontHeightInPoints"
:
12
fontHeightInPoints
:
12
,
},
},
"alignment"
:
"CENTER"
,
alignment
:
'CENTER'
,
"borderLeft"
:
"THIN"
,
borderLeft
:
'THIN'
,
"borderTop"
:
"THIN"
,
borderTop
:
'THIN'
,
"borderBottom"
:
"THIN"
,
borderBottom
:
'THIN'
,
"borderRight"
:
"THIN"
,
borderRight
:
'THIN'
,
"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
:
200
,
},
head
:
{
font
:
{
bold
:
true
,
},
alignment
:
'CENTER'
,
},
},
"head"
:
{
"font"
:
{
"bold"
:
true
},
},
"alignment"
:
"CENTER"
,
}
}
};
};
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
...
@@ -241,18 +280,21 @@ export default function getColumnsSqlKeyRealize(sqlKey, columns, styles, fileNam
...
@@ -241,18 +280,21 @@ export default function getColumnsSqlKeyRealize(sqlKey, columns, styles, fileNam
let
getFileData
=
giveFilePostDataInfoForTrue
(
let
getFileData
=
giveFilePostDataInfoForTrue
(
{
{
content
:
JSON
.
stringify
(
content
),
content
:
JSON
.
stringify
(
content
),
title
:
fileName
title
:
fileName
,
},
},
`
${
window
.
location
.
origin
}
/produce/v1/api/onestop
${
url
}
`
`
${
queryOauthActionPath
()
+
'/DataObjApi/exportCustom'
}
`
,
);
);
let
token
=
localStorage
.
getItem
(
'antd-pro-token-onestop'
);
let
token
=
getToken
();
downloadFile
(
getFileData
.
url
,
{
downloadFile
(
getFileData
.
url
,
{
...
getFileData
.
datas
,
...
getFileData
.
datas
,
token
:
token
token
:
token
,
},
fileName
,
ext
);
},
fileName
,
};
ext
,
);
}
/**
/**
* 表头和数据导出(合并表格)
* 表头和数据导出(合并表格)
...
@@ -266,71 +308,93 @@ export default function getColumnsSqlKeyRealize(sqlKey, columns, styles, fileNam
...
@@ -266,71 +308,93 @@ export default function getColumnsSqlKeyRealize(sqlKey, columns, styles, fileNam
* eliminateStr : 忽略合并的值
* eliminateStr : 忽略合并的值
* 返回值
* 返回值
* */
* */
export
default
function
getColumnsDataRealize
(
data
=
[],
mergeKey
=
[],
columns
,
styles
,
defect
=
null
,
fileName
=
"导出文件"
,
ext
=
'xlsx'
,
url
=
`/DataObjApi/exportCustom`
,
eliminateStr
=
[])
{
export
function
getColumnsDataRealize
({
let
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
data
=
[],
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
(
mergeKey
,
data
,
eliminateStr
);
mergeKey
=
[],
columns
,
styles
,
defect
=
null
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
eliminateStr
=
[],
})
{
let
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
(
mergeKey
,
data
,
eliminateStr
);
// 处理数据
// 处理数据
let
bodyData
=
[];
let
bodyData
=
[];
const
uj
=
{
"t"
:
1
,
"v"
:
"序号"
,
s
:
"header"
};
const
uj
=
{
t
:
1
,
v
:
'序号'
,
s
:
'header'
,
};
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
)
=>
{
nowArroy
[
ai
]
=
{
nowArroy
[
ai
]
=
{
...
uj
,
...
uj
,
v
:
av
in
dv
?
dv
[
av
].
toString
()
:
(
defect
||
""
)
v
:
av
in
dv
?
dv
[
av
].
toString
()
:
defect
||
''
,
};
};
});
});
bodyData
.
push
(
nowArroy
);
bodyData
.
push
(
nowArroy
);
})
});
// 处理合并数据
// 处理合并数据
let
dataMerges
=
[];
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
)
{
//合并表格的 开始行、结束行、开始列、结束列
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
+
cv
-
1
,
rowIndex
,
rowIndex
]);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
+
cv
-
1
,
rowIndex
,
rowIndex
]);
}
}
});
});
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
}
});
});
});
});
let
content
=
{
let
content
=
{
"sheets"
:
[
sheets
:
[
{
{
"name"
:
fileName
,
name
:
fileName
,
"cells"
:
[...
columnsList
,
...
bodyData
],
cells
:
[...
columnsList
,
...
bodyData
],
"merges"
:
[...
columnsMerges
,
...
dataMerges
]
merges
:
[...
columnsMerges
,
...
dataMerges
],
}
},
],
],
"styles"
:
{
styles
:
{
"header"
:
{
header
:
{
"font"
:
{
font
:
{
"bold"
:
false
,
bold
:
false
,
"fontHeightInPoints"
:
12
fontHeightInPoints
:
12
,
},
},
"alignment"
:
"CENTER"
,
alignment
:
'CENTER'
,
"borderLeft"
:
"THIN"
,
borderLeft
:
'THIN'
,
"borderTop"
:
"THIN"
,
borderTop
:
'THIN'
,
"borderBottom"
:
"THIN"
,
borderBottom
:
'THIN'
,
"borderRight"
:
"THIN"
,
borderRight
:
'THIN'
,
"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
:
200
,
},
head
:
{
font
:
{
bold
:
true
,
},
alignment
:
'CENTER'
,
},
},
"head"
:
{
"font"
:
{
"bold"
:
true
},
},
"alignment"
:
"CENTER"
,
}
}
};
};
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
...
@@ -338,17 +402,21 @@ export default function getColumnsDataRealize(data = [], mergeKey = [], columns,
...
@@ -338,17 +402,21 @@ export default function getColumnsDataRealize(data = [], mergeKey = [], columns,
let
getFileData
=
giveFilePostDataInfoForTrue
(
let
getFileData
=
giveFilePostDataInfoForTrue
(
{
{
content
:
JSON
.
stringify
(
content
),
content
:
JSON
.
stringify
(
content
),
title
:
fileName
title
:
fileName
,
},
},
`
${
window
.
location
.
origin
}
/produce/v1/api/onestop
${
url
}
`
`
${
queryOauthActionPath
()
+
'/DataObjApi/exportCustom'
}
`
,
);
);
let
token
=
localStorage
.
getItem
(
'antd-pro-token-onestop'
);
let
token
=
localStorage
.
getItem
(
'antd-pro-token-onestop'
);
downloadFile
(
getFileData
.
url
,
{
downloadFile
(
getFileData
.
url
,
{
...
getFileData
.
datas
,
...
getFileData
.
datas
,
token
:
token
token
:
token
,
},
fileName
,
ext
);
},
};
fileName
,
ext
,
);
}
/**
/**
* 表头和数据导出(合并表格)
* 表头和数据导出(合并表格)
...
@@ -360,61 +428,94 @@ export default function getColumnsDataRealize(data = [], mergeKey = [], columns,
...
@@ -360,61 +428,94 @@ export default function getColumnsDataRealize(data = [], mergeKey = [], columns,
* ext : 导出后缀 目前xecl、dbf
* ext : 导出后缀 目前xecl、dbf
* 返回值
* 返回值
* */
* */
export
default
function
getWord
(
templatePath
,
params
,
title
,
allValues
=
{},
listConfig
=
{},
ext
=
'docx'
)
{
export
function
getWord
({
templatePath
,
params
,
title
,
allValues
=
{},
listConfig
=
{},
ext
=
'docx'
,
}
)
{
//可更新的
//可更新的
let
getFileData
=
giveFilePostDataInfoForTrue
(
let
getFileData
=
giveFilePostDataInfoForTrue
(
{
{
templatePath
:
"/u/templateOnestop/SXH.docx"
,
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
}),
},
},
`
${
window
.
location
.
origin
}
/produce/v1/api/onestop`
+
`/DataColumnApi/exportWord`
`
${
queryOauthActionPath
()}
`
+
`/DataColumnApi/exportWord`
,
);
);
let
token
=
localStorage
.
getItem
(
'antd-pro-token-onestop'
);
let
token
=
getToken
();
downloadFile
(
getFileData
.
url
,
{
downloadFile
(
getFileData
.
url
,
{
...
getFileData
.
datas
,
...
getFileData
.
datas
,
token
:
token
token
:
token
,
},
title
,
ext
);
},
title
,
ext
,
);
function
setObjectKey
(
data
)
{
function
setObjectKey
(
data
)
{
return
Object
.
keys
(
data
)
return
(
Object
.
keys
(
data
)
//.filter((key) => data[key] !== null && data[key] !== undefined)
//.filter((key) => data[key] !== null && data[key] !== undefined)
.
reduce
((
acc
,
key
)
=>
({
...
acc
,
[
"${"
+
key
+
"}"
]:
(
data
[
key
]
===
null
?
""
:
data
[
key
])
}),
{});
.
reduce
(
(
acc
,
key
)
=>
({
...
acc
,
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
}),
{},
)
);
}
}
}
}
// 下载附件FormdataWrapper
function
isObject
(
value
)
{
return
value
===
Object
(
value
);
}
function
isArray
(
value
)
{
return
Array
.
isArray
(
value
);
}
function
isFile
(
value
)
{
return
value
instanceof
File
;
}
function
makeArrayKey
(
key
)
{
return
key
;
}
// 下载附件FormdataWrapper
function
isObject
(
value
)
{
return
value
===
Object
(
value
)
}
function
isArray
(
value
)
{
return
Array
.
isArray
(
value
)
}
function
isFile
(
value
)
{
return
value
instanceof
File
}
function
makeArrayKey
(
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
)
var
key
=
pre
?
(
pre
+
'['
+
prop
+
']'
)
:
prop
.
forEach
(
function
(
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
,
{
...
@@ -438,7 +539,8 @@ function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
...
@@ -438,7 +539,8 @@ function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
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
);
...
@@ -446,4 +548,4 @@ function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
...
@@ -446,4 +548,4 @@ function downloadFile(url, params, fileName = '导出文件', ext = 'xlsx') {
.
finally
(()
=>
{
.
finally
(()
=>
{
return
true
;
return
true
;
});
});
};
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论