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

批量下载word通用接口

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