提交 409c9f9a authored 作者: 姚鑫国's avatar 姚鑫国

批量下载word通用接口

上级 a516288c
......@@ -23,11 +23,11 @@ const apiUrl = queryOauthActionPath();
* rowSpanData 列合并数据,colSpanData行合并数据
* */
export function getSpanJson({
mergeKey,
data,
eliminateRow = [],
eliminateCol = []
}) {
mergeKey,
data,
eliminateRow = [],
eliminateCol = []
}) {
try {
let dataList = deepCopy(data);
......@@ -260,13 +260,13 @@ export function getColumns(columns) {
* url : 接口地址
*/
export function getColumnsSqlKeyRealize({
sqlKey,
columns,
styles,
fileName = '导出文件',
ext = 'xlsx',
allValues = JSON.stringify({})
}) {
sqlKey,
columns,
styles,
fileName = '导出文件',
ext = 'xlsx',
allValues = JSON.stringify({})
}) {
columns = deepCopy(columns);
let {
......@@ -283,7 +283,7 @@ export function getColumnsSqlKeyRealize({
merges: columnsMerges,
sqlKey: sqlKey, //sql编码
sqlKeyHeader: columnsKey, //sql对应key对应列
allValues:allValues
allValues: allValues
},
],
styles: {
......@@ -352,16 +352,16 @@ export function getColumnsSqlKeyRealize({
*
*/
export function getColumnsDataRealize({
data = [],
mergeKey = [],
columns,
styles,
defect = null,
fileName = '导出文件',
ext = 'xlsx',
eliminateRow = [],
eliminateCol = [],
}) {
data = [],
mergeKey = [],
columns,
styles,
defect = null,
fileName = '导出文件',
ext = 'xlsx',
eliminateRow = [],
eliminateCol = [],
}) {
columns = deepCopy(columns);
data = deepCopy(data);
let {
......@@ -539,13 +539,13 @@ export function renderContentRow(value, row, index, key, spanData, cloumnNames =
* 返回值
* */
export function getWord({
templatePath,
params,
title,
allValues = {},
listConfig = {},
ext = 'docx',
}) {
templatePath,
params,
title,
allValues = {},
listConfig = {},
ext = 'docx',
}) {
try {
let getFileData = giveFilePostDataInfoForTrue(
{
......@@ -572,22 +572,7 @@ export function getWord({
} catch (err) {
console.table(err);
}
//可更新的
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],
}),
{},
)
);
}
}
......@@ -602,13 +587,13 @@ export function getWord({
* 返回值
* */
export function getFileAndShow({
templatePath,
params,
title,
allValues = {},
listConfig = {},
ext = 'docx',
}) {
templatePath,
params,
title,
allValues = {},
listConfig = {},
ext = 'docx',
}) {
try {
let getFileData = giveFilePostDataInfoForTrue(
{
......@@ -635,24 +620,96 @@ export function getFileAndShow({
} catch (err) {
console.table(err);
}
}
//可更新的
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],
}),
{},
)
/**
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
* params : word文档的替换参数
* title : 导出文件名
* allValues : sql参数
* listConfig : 导出列表配置
* ext : 导出后缀 目前xecl、dbf,docx,pdf
* 返回值
* */
export function getListWord({
templatePath,
paramsList = [],
title,
sonTitleKey,
allValuesKey = [],
listConfig = {},
ext = 'zip',
sonExt = 'pdf',
}) {
try {
let content = [];
paramsList.forEach((v, i) => {
content.push({
params: {
...setObjectKey(v),
...listConfig,
},
allValues: {
...getObjectsKey(allValuesKey, v)
},
title: (v[sonTitleKey] || "未设置名称") + `.${sonExt}`
});
});
let getFileData = giveFilePostDataInfoForTrue(
{
templatePath: templatePath,
content: JSON.stringify(content),
zipTitle: `${title}.${ext}`,
},
apiUrl + `/DataColumnApi/batchExportWord`,
);
let token = getToken();
downloadFile(
getFileData.url,
{
...getFileData.datas,
token: token,
},
title,
ext,
);
} catch (err) {
console.table(err);
}
function getObjectsKey(listKey = [], params = {}) {
return (
listKey
.filter((key) => Object.keys(params).indexOf(key)
.reduce(
(acc, key) => ({
...acc,
[key]: params[key] === null ? '' : params[key],
}),
{},
))
)
}
}
function setObjectKey(data) {
return (
Object.keys(data)
.reduce(
(acc, key) => ({
...acc,
['${' + key + '}']: data[key] === null ? '' : data[key],
}),
{},
)
);
}
// 下载附件FormdataWrapper
function isObject(value) {
......@@ -762,14 +819,14 @@ export function downloadFileAndShowModal(url, params, fileName = '导出文件',
width: 1000,
content: <div>
<embed width='100%'
height='568px'
name='plugin'
id='pdfView'
src={url}
type='application/pdf'
internalinstanceid='3'
title={filename}/>
height='568px'
name='plugin'
id='pdfView'
src={url}
type='application/pdf'
internalinstanceid='3'
title={filename} />
</div>,
okText: '确定',
onCancel: () => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论