Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
a5b400d0
提交
a5b400d0
authored
6月 01, 2022
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加公共函数
上级
bfa4224f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
424 行增加
和
444 行删除
+424
-444
globalFunction.js
one_stop_public/Table/globalFunction.js
+424
-444
没有找到文件。
one_stop_public/Table/globalFunction.js
浏览文件 @
a5b400d0
...
...
@@ -17,96 +17,96 @@ 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
),
};
return
{
rowSpanData
:
getRowSpanJson
(
mergeKey
,
data
,
eliminateStr
),
colSpanData
:
getColSpanJson
(
mergeKey
,
data
,
eliminateStr
),
};
}
function
getRowSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//纵向合并
// 获取列的 dataIndex 集合
var
rowSpanJson
=
{};
//保存上一个name
var
beforeNameMap
=
{};
//相同name出现的次数
var
countMap
=
{};
//该name第一次出现的位置
var
startIndexMap
=
{};
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
var
dataItem
=
data
[
idx
];
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
var
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
beforeNameMap
[
keyItem
]
=
dataItem
[
keyItem
];
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
)
{
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
rowSpanJson
[
keyItem
][
idx
]
=
0
;
}
else
{
countMap
[
keyItem
]
=
1
;
beforeNameMap
[
keyItem
]
=
dataItemValue
;
startIndexMap
[
keyItem
]
=
idx
;
//纵向合并
// 获取列的 dataIndex 集合
var
rowSpanJson
=
{};
//保存上一个name
var
beforeNameMap
=
{};
//相同name出现的次数
var
countMap
=
{};
//该name第一次出现的位置
var
startIndexMap
=
{};
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
var
dataItem
=
data
[
idx
];
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
var
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
beforeNameMap
[
keyItem
]
=
dataItem
[
keyItem
];
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
)
{
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
rowSpanJson
[
keyItem
][
idx
]
=
0
;
}
else
{
countMap
[
keyItem
]
=
1
;
beforeNameMap
[
keyItem
]
=
dataItemValue
;
startIndexMap
[
keyItem
]
=
idx
;
rowSpanJson
[
keyItem
][
idx
]
=
1
;
}
}
}
return
rowSpanJson
;
rowSpanJson
[
keyItem
][
idx
]
=
1
;
}
}
}
return
rowSpanJson
;
}
function
getColSpanJson
(
cloumnNames
,
data
,
eliminateStr
=
[])
{
//横向合并
var
colSpanJson
=
{};
for
(
let
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
let
dataItem
=
data
[
idx
];
let
colSum
=
1
;
//宽度
let
triggerColIndex
=
null
;
//记录触发时得位置
let
triggerColSum
=
1
;
//记录触发时得位置
let
isCol
=
false
;
for
(
let
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
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
(
getRowSpanJson
.
length
);
}
if
(
!
isCol
&&
dataItemValue
===
dataItemValueNext
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
)
{
//触发合并
triggerColIndex
=
keyItem
;
isCol
=
true
;
}
if
(
isCol
&&
(
dataItemValue
!==
dataItemValueNext
||
dataItemValueNext
==
null
))
{
//合并结束
isCol
=
false
;
}
if
(
isCol
)
{
//计数
triggerColSum
++
;
}
if
(
!
isCol
&&
triggerColIndex
!==
null
)
{
colSpanJson
[
triggerColIndex
][
idx
]
=
triggerColSum
;
colSpanJson
[
keyItem
][
idx
]
=
0
;
triggerColIndex
=
null
;
}
else
{
colSpanJson
[
keyItem
][
idx
]
=
colSum
;
}
}
}
//console.log("colSpanJson",colSpanJson)
return
colSpanJson
;
//横向合并
var
colSpanJson
=
{};
for
(
let
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
let
dataItem
=
data
[
idx
];
let
colSum
=
1
;
//宽度
let
triggerColIndex
=
null
;
//记录触发时得位置
let
triggerColSum
=
1
;
//记录触发时得位置
let
isCol
=
false
;
for
(
let
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
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
(
getRowSpanJson
.
length
);
}
if
(
!
isCol
&&
dataItemValue
===
dataItemValueNext
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
)
{
//触发合并
triggerColIndex
=
keyItem
;
isCol
=
true
;
}
if
(
isCol
&&
(
dataItemValue
!==
dataItemValueNext
||
dataItemValueNext
==
null
))
{
//合并结束
isCol
=
false
;
}
if
(
isCol
)
{
//计数
triggerColSum
++
;
}
if
(
!
isCol
&&
triggerColIndex
!==
null
)
{
colSpanJson
[
triggerColIndex
][
idx
]
=
triggerColSum
;
colSpanJson
[
keyItem
][
idx
]
=
0
;
triggerColIndex
=
null
;
}
else
{
colSpanJson
[
keyItem
][
idx
]
=
colSum
;
}
}
}
//console.log("colSpanJson",colSpanJson)
return
colSpanJson
;
}
/**
...
...
@@ -120,101 +120,95 @@ function getColSpanJson(cloumnNames, data, eliminateStr = []) {
* columnsHeight 行数
* */
export
function
getColumns
(
columns
)
{
const
uj
=
{
t
:
1
,
v
:
'序号'
,
s
:
'header'
,
};
let
columnsHeight
=
0
;
getColumnsMaxLevel
(
columns
);
//递归行数
let
columnsKey
=
[];
const
columnsList
=
new
Array
(
columnsHeight
).
fill
([]);
let
col
=
1
;
for
(
var
i
in
columnsList
)
{
columnsList
[
i
]
=
new
Array
(
getColumnsWidth
(
columns
)).
fill
({});
}
const
uj
=
{
t
:
1
,
v
:
'序号'
,
s
:
'header'
,
};
let
columnsHeight
=
0
;
getColumnsMaxLevel
(
columns
);
//递归行数
let
columnsKey
=
[];
const
columnsList
=
new
Array
(
columnsHeight
).
fill
([]);
let
col
=
1
;
for
(
var
i
in
columnsList
)
{
columnsList
[
i
]
=
new
Array
(
getColumnsWidth
(
columns
)).
fill
({});
}
function
getColumnsData
(
data
=
[],
res
=
[],
level
=
1
)
{
for
(
let
item
of
data
)
{
//item.key = i;
let
isLast
=
!
item
.
children
;
item
.
level
=
level
;
item
.
isLast
=
isLast
;
item
.
width
=
!
isLast
?
getColumnsWidth
(
item
.
children
)
:
1
;
item
.
col
=
col
;
res
.
push
(
item
);
columnsList
[
level
-
1
][
col
-
1
]
=
{
...
uj
,
v
:
item
.
title
,
};
if
(
!
isLast
)
{
if
(
Array
.
isArray
(
item
.
children
))
{
let
x
=
level
+
1
;
getColumnsData
(
item
.
children
,
res
,
x
);
}
}
else
{
col
++
;
columnsKey
.
push
(
item
[
'dataIndex'
]);
}
}
return
res
;
}
function
getColumnsData
(
data
=
[],
res
=
[],
level
=
1
)
{
for
(
let
item
of
data
)
{
//item.key = i;
let
isLast
=
!
item
.
children
;
item
.
level
=
level
;
item
.
isLast
=
isLast
;
item
.
width
=
!
isLast
?
getColumnsWidth
(
item
.
children
)
:
1
;
item
.
col
=
col
;
res
.
push
(
item
);
columnsList
[
level
-
1
][
col
-
1
]
=
{
...
uj
,
v
:
item
.
title
,
};
if
(
!
isLast
)
{
if
(
Array
.
isArray
(
item
.
children
))
{
let
x
=
level
+
1
;
getColumnsData
(
item
.
children
,
res
,
x
);
}
}
else
{
col
++
;
columnsKey
.
push
(
item
[
'dataIndex'
]);
}
}
return
res
;
}
//递归行数
function
getColumnsMaxLevel
(
data
=
[],
level
=
1
)
{
for
(
let
item
of
data
)
{
let
isLast
=
!
item
.
children
;
if
(
!
isLast
&&
Array
.
isArray
(
item
.
children
))
{
let
x
=
level
+
1
;
if
(
columnsHeight
<
x
)
{
columnsHeight
=
x
;
}
getColumnsMaxLevel
(
item
.
children
,
x
);
}
}
return
level
;
}
//递归行数
function
getColumnsMaxLevel
(
data
=
[],
level
=
1
)
{
for
(
let
item
of
data
)
{
let
isLast
=
!
item
.
children
;
if
(
!
isLast
&&
Array
.
isArray
(
item
.
children
))
{
let
x
=
level
+
1
;
if
(
columnsHeight
<
x
)
{
columnsHeight
=
x
;
}
getColumnsMaxLevel
(
item
.
children
,
x
);
}
}
return
level
;
}
//递归当前数据宽度
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
for
(
let
item
of
data
)
{
if
(
!
item
.
children
)
{
sum
++
;
}
else
{
sum
=
getColumnsWidth
(
item
.
children
,
sum
);
}
}
return
sum
;
}
//递归当前数据宽度
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
for
(
let
item
of
data
)
{
if
(
!
item
.
children
)
{
sum
++
;
}
else
{
sum
=
getColumnsWidth
(
item
.
children
,
sum
);
}
}
return
sum
;
}
let
columnsHandle
=
getColumnsData
(
columns
)
.
filter
((
v
,
i
)
=>
{
return
(
v
.
level
<
columnsHeight
&&
v
.
isLast
)
||
v
.
width
>
1
;
});
let
columnsMerges
=
[];
columnsHandle
.
forEach
((
v
,
i
)
=>
{
let
{
isLast
,
width
,
col
,
level
}
=
v
;
let
nowCol
=
col
-
1
;
let
nowLevel
=
level
-
1
;
if
(
isLast
&&
width
===
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
columnsMerges
.
push
([
nowLevel
,
columnsHeight
-
1
,
nowCol
,
nowCol
]);
}
if
(
!
isLast
&&
width
>
1
)
{
columnsMerges
.
push
([
nowLevel
,
nowLevel
,
nowCol
,
nowCol
+
width
-
1
]);
}
});
return
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
,
};
let
columnsHandle
=
getColumnsData
(
columns
).
filter
((
v
,
i
)
=>
{
return
(
v
.
level
<
columnsHeight
&&
v
.
isLast
)
||
v
.
width
>
1
;
});
let
columnsMerges
=
[];
columnsHandle
.
forEach
((
v
,
i
)
=>
{
let
{
isLast
,
width
,
col
,
level
}
=
v
;
let
nowCol
=
col
-
1
;
let
nowLevel
=
level
-
1
;
if
(
isLast
&&
width
===
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
columnsMerges
.
push
([
nowLevel
,
columnsHeight
-
1
,
nowCol
,
nowCol
]);
}
if
(
!
isLast
&&
width
>
1
)
{
columnsMerges
.
push
([
nowLevel
,
nowLevel
,
nowCol
,
nowCol
+
width
-
1
]);
}
});
return
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
,
};
}
/**
...
...
@@ -229,71 +223,67 @@ export function getColumns(columns) {
* 返回值
* */
export
function
getColumnsSqlKeyRealize
({
sqlKey
,
columns
,
styles
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
})
{
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
content
=
{
sheets
:
[
{
name
:
fileName
,
cells
:
columnsList
,
merges
:
columnsMerges
,
sqlKey
:
sqlKey
,
//sql编码
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
],
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
:
200
,
},
head
:
{
font
:
{
bold
:
true
,
},
alignment
:
'CENTER'
,
},
},
};
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
,
);
sqlKey
,
columns
,
styles
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
})
{
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
content
=
{
sheets
:
[
{
name
:
fileName
,
cells
:
columnsList
,
merges
:
columnsMerges
,
sqlKey
:
sqlKey
,
//sql编码
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
],
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
:
200
,
},
head
:
{
font
:
{
bold
:
true
,
},
alignment
:
'CENTER'
,
},
},
};
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
,
);
}
/**
...
...
@@ -309,113 +299,105 @@ export function getColumnsSqlKeyRealize({
* 返回值
* */
export
function
getColumnsDataRealize
({
data
=
[],
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
=
[];
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
].
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
]);
}
});
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
});
});
data
=
[],
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
=
[];
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
].
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
]);
}
});
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
//合并表格的 开始行、结束行、开始列、结束列
let
rowIndex
=
columnsKey
.
indexOf
(
mv
);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
});
});
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
:
200
,
},
head
:
{
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
,
);
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
:
200
,
},
head
:
{
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
,
);
}
/**
...
...
@@ -429,123 +411,121 @@ export function getColumnsDataRealize({
* 返回值
* */
export
function
getWord
({
templatePath
,
params
,
title
,
allValues
=
{},
listConfig
=
{},
ext
=
'docx'
,
}
)
{
//可更新的
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
,
);
templatePath
,
params
,
title
,
allValues
=
{},
listConfig
=
{},
ext
=
'docx'
,
})
{
//可更新的
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
)
//.filter((key) => data[key] !== null && data[key] !== undefined)
.
reduce
(
(
acc
,
key
)
=>
({
...
acc
,
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
}),
{},
)
);
}
function
setObjectKey
(
data
)
{
return
(
Object
.
keys
(
data
)
//.filter((key) => data[key] !== null && data[key] !== undefined)
.
reduce
(
(
acc
,
key
)
=>
({
...
acc
,
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
}),
{},
)
);
}
}
// 下载附件FormdataWrapper
function
isObject
(
value
)
{
return
value
===
Object
(
value
);
return
value
===
Object
(
value
);
}
function
isArray
(
value
)
{
return
Array
.
isArray
(
value
);
return
Array
.
isArray
(
value
);
}
function
isFile
(
value
)
{
return
value
instanceof
File
;
return
value
instanceof
File
;
}
function
makeArrayKey
(
key
)
{
return
key
;
return
key
;
}
function
FormdataWrapper
(
obj
,
fd
,
pre
)
{
fd
=
fd
||
new
FormData
();
Object
.
keys
(
obj
)
.
forEach
(
function
(
prop
)
{
var
key
=
pre
?
pre
+
'['
+
prop
+
']'
:
prop
;
if
(
isObject
(
obj
[
prop
])
&&
!
isArray
(
obj
[
prop
])
&&
!
isFile
(
obj
[
prop
]))
{
FormdataWrapper
(
obj
[
prop
],
fd
,
key
);
}
else
if
(
isArray
(
obj
[
prop
]))
{
obj
[
prop
].
forEach
(
function
(
value
)
{
var
arrayKey
=
makeArrayKey
(
key
);
if
(
isObject
(
value
)
&&
!
isFile
(
value
))
{
FormdataWrapper
(
value
,
fd
,
arrayKey
);
}
else
{
fd
.
append
(
arrayKey
,
value
);
}
});
}
else
{
if
(
obj
[
prop
]
!=
null
)
fd
.
append
(
key
,
obj
[
prop
]);
}
});
return
fd
;
fd
=
fd
||
new
FormData
();
Object
.
keys
(
obj
).
forEach
(
function
(
prop
)
{
var
key
=
pre
?
pre
+
'['
+
prop
+
']'
:
prop
;
if
(
isObject
(
obj
[
prop
])
&&
!
isArray
(
obj
[
prop
])
&&
!
isFile
(
obj
[
prop
]))
{
FormdataWrapper
(
obj
[
prop
],
fd
,
key
);
}
else
if
(
isArray
(
obj
[
prop
]))
{
obj
[
prop
].
forEach
(
function
(
value
)
{
var
arrayKey
=
makeArrayKey
(
key
);
if
(
isObject
(
value
)
&&
!
isFile
(
value
))
{
FormdataWrapper
(
value
,
fd
,
arrayKey
);
}
else
{
fd
.
append
(
arrayKey
,
value
);
}
});
}
else
{
if
(
obj
[
prop
]
!=
null
)
fd
.
append
(
key
,
obj
[
prop
]);
}
});
return
fd
;
}
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
// console.log("downloadFile",url);
fetch
(
url
,
{
method
:
'POST'
,
body
:
FormdataWrapper
(
params
),
})
.
then
((
res
)
=>
{
if
(
res
.
status
+
''
!==
'200'
)
{
return
res
.
json
();
}
else
{
return
res
.
blob
();
}
})
.
then
((
data
)
=>
{
if
(
data
instanceof
Blob
)
{
let
a
=
document
.
createElement
(
'a'
);
let
url
=
window
.
URL
.
createObjectURL
(
data
);
let
filename
=
fileName
+
'.'
+
ext
;
a
.
href
=
url
;
a
.
download
=
filename
;
a
.
click
();
window
.
URL
.
revokeObjectURL
(
url
);
a
=
null
;
}
else
{
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
})
.
finally
(()
=>
{
return
true
;
});
// console.log("downloadFile",url);
fetch
(
url
,
{
method
:
'POST'
,
body
:
FormdataWrapper
(
params
),
})
.
then
((
res
)
=>
{
if
(
res
.
status
+
''
!==
'200'
)
{
return
res
.
json
();
}
else
{
return
res
.
blob
();
}
})
.
then
((
data
)
=>
{
if
(
data
instanceof
Blob
)
{
let
a
=
document
.
createElement
(
'a'
);
let
url
=
window
.
URL
.
createObjectURL
(
data
);
let
filename
=
fileName
+
'.'
+
ext
;
a
.
href
=
url
;
a
.
download
=
filename
;
a
.
click
();
window
.
URL
.
revokeObjectURL
(
url
);
a
=
null
;
}
else
{
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
})
.
finally
(()
=>
{
return
true
;
});
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论