Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
cfc0faf3
提交
cfc0faf3
authored
11月 04, 2024
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
4023 医保--参保通知批量下载功能优化
上级
3f5508dd
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
210 行增加
和
168 行删除
+210
-168
globalFunction.js
one_stop_public/Table/globalFunction.js
+163
-168
utils.js
one_stop_public/Table/utils.js
+47
-0
没有找到文件。
one_stop_public/Table/globalFunction.js
浏览文件 @
cfc0faf3
...
...
@@ -5,9 +5,8 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token';
import
{
deepCopy
}
from
'@/webPublic/zyd_public/utils/utils'
;
import
{
getTransformApi
}
from
'@/webPublic/one_stop_public/2022beidianke/localstorageTransform'
;
import
moment
from
'moment'
;
import
{
getSassApiHeader
,
}
from
'@/webPublic/one_stop_public/2023yunshangguizhou/utils'
;
import
{
getSassApiHeader
}
from
'@/webPublic/one_stop_public/2023yunshangguizhou/utils'
;
import
{
showDownloadProgressFromFileName
}
from
"./utils"
;
const
apiUrl
=
queryOauthActionPath
();
export
{
apiUrl
};
...
...
@@ -39,7 +38,7 @@ const uj = {
t
:
1
,
v
:
'序号'
,
s
:
'header'
,
w
:
20
//默认值是20像素
w
:
20
,
//默认值是20像素
};
/**
* 公共函数代码
...
...
@@ -62,31 +61,35 @@ export function getSpanJson({
eliminateRow
=
[],
eliminateCol
=
[],
mergePrimaryRow
,
mergeMappingRow
=
{}
// 某一列的合并数据 复制 到任意其他列
mergeMappingRow
=
{},
// 某一列的合并数据 复制 到任意其他列
})
{
const
dataList
=
deepCopy
(
data
);
let
rowSpanData
,
colSpanData
=
null
;
let
rowSpanData
,
colSpanData
=
null
;
try
{
rowSpanData
=
getRowSpanJson
(
mergeKey
,
dataList
,
eliminateRow
,
mergePrimaryRow
);
}
catch
(
err
)
{
console
.
table
(
"rowSpanData"
,
err
);
console
.
table
(
'rowSpanData'
,
err
);
}
try
{
colSpanData
=
getColSpanJson
(
mergeKey
,
dataList
,
eliminateCol
);
}
catch
(
err
)
{
console
.
table
(
"colSpanData"
,
err
);
console
.
table
(
'colSpanData'
,
err
);
}
try
{
const
newMergeMappingRow
=
Object
.
keys
(
mergeMappingRow
).
filter
(
item1
=>
mergeKey
.
some
(
item2
=>
item2
===
item1
));
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
));
const
mappingList
=
mergeMappingRow
[
item
].
filter
(
(
item1
)
=>
!
mergeKey
.
some
((
item2
)
=>
item2
===
item1
),
);
mappingList
.
map
((
mItem
)
=>
{
rowSpanData
[
mItem
]
=
rowSpanData
[
item
];
});
});
}
catch
(
e
)
{
console
.
table
(
"mergeMappingRow"
,
e
);
console
.
table
(
'mergeMappingRow'
,
e
);
}
return
{
rowSpanData
,
...
...
@@ -107,16 +110,18 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
var
startIndexMap
=
{};
// 是否主键模式
var
isPrimary
=
false
;
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 循环数据
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 循环数据
var
dataItem
=
data
[
idx
];
var
dataItemRowValue
;
var
dataItemPreviousRowValue
;
if
(
mergePrimaryRow
)
{
isPrimary
=
true
;
//开启主键模式
isPrimary
=
true
;
//开启主键模式
dataItemRowValue
=
dataItem
[
mergePrimaryRow
];
dataItemPreviousRowValue
=
data
[
idx
-
1
>
0
?
idx
-
1
:
0
][
mergePrimaryRow
];
}
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
// 循环表头
for
(
var
idj
=
0
;
idj
<
cloumnNames
.
length
;
idj
++
)
{
// 循环表头
var
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
...
...
@@ -128,8 +133,11 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
continue
;
}
if
(
(
!
isPrimary
?
(
dataItemValue
===
beforeNameMap
[
keyItem
])
:
(
dataItemRowValue
+
dataItemValue
===
dataItemPreviousRowValue
+
beforeNameMap
[
keyItem
]))
// 与上一个值一致时
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
// 排除特定的值合并
(
!
isPrimary
?
dataItemValue
===
beforeNameMap
[
keyItem
]
:
dataItemRowValue
+
dataItemValue
===
dataItemPreviousRowValue
+
beforeNameMap
[
keyItem
])
&&
// 与上一个值一致时
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
// 排除特定的值合并
)
{
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
...
...
@@ -239,7 +247,7 @@ export function getColumns(columns) {
}
return
res
;
}
catch
(
e
)
{
console
.
table
(
"getColumnsDatas"
,
e
);
console
.
table
(
'getColumnsDatas'
,
e
);
return
[];
}
}
...
...
@@ -264,7 +272,6 @@ export function getColumns(columns) {
return
maxLevel
;
}
//递归当前数据宽度
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
for
(
let
item
of
data
)
{
...
...
@@ -277,18 +284,12 @@ export function getColumns(columns) {
return
sum
;
}
let
columnsHandle
=
getColumnsDatas
(
columns
)
.
filter
((
v
,
i
)
=>
{
let
columnsHandle
=
getColumnsDatas
(
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
{
isLast
,
width
,
col
,
level
}
=
v
;
let
nowCol
=
col
-
1
;
let
nowLevel
=
level
-
1
;
if
(
isLast
&&
width
===
1
)
{
...
...
@@ -324,15 +325,11 @@ export function getColumnsSqlKeyRealize({
styles
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
allValues
=
JSON
.
stringify
({})
allValues
=
JSON
.
stringify
({}),
})
{
columns
=
deepCopy
(
columns
);
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
content
=
{
sheets
:
[
...
...
@@ -344,7 +341,7 @@ export function getColumnsSqlKeyRealize({
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
],
styles
:
exportStyles
styles
:
exportStyles
,
};
if
(
styles
)
{
content
.
styles
=
styles
;
...
...
@@ -354,7 +351,7 @@ export function getColumnsSqlKeyRealize({
{
content
:
JSON
.
stringify
(
content
),
title
:
fileName
,
allValues
:
allValues
allValues
:
allValues
,
},
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
);
...
...
@@ -369,11 +366,10 @@ export function getColumnsSqlKeyRealize({
ext
,
);
}
catch
(
err
)
{
console
.
table
(
"getColumnsSqlKeyRealize"
,
err
);
console
.
table
(
'getColumnsSqlKeyRealize'
,
err
);
}
}
/**
*
* @param {sqlKey,columnsList,columnsMerges,columnsKey,styles,fileName,ext,allValues} param
...
...
@@ -395,7 +391,7 @@ export function getCustomSqlKeyRealize({
styles
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
allValues
=
JSON
.
stringify
({})
allValues
=
JSON
.
stringify
({}),
})
{
let
content
=
{
sheets
:
[
...
...
@@ -407,7 +403,7 @@ export function getCustomSqlKeyRealize({
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
],
styles
:
exportStyles
styles
:
exportStyles
,
};
if
(
styles
)
{
content
.
styles
=
styles
;
...
...
@@ -417,7 +413,7 @@ export function getCustomSqlKeyRealize({
{
content
:
JSON
.
stringify
(
content
),
title
:
fileName
,
allValues
:
allValues
allValues
:
allValues
,
},
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
);
...
...
@@ -432,7 +428,7 @@ export function getCustomSqlKeyRealize({
ext
,
);
}
catch
(
err
)
{
console
.
table
(
"getCustomSqlKeyRealize"
,
err
);
console
.
table
(
'getCustomSqlKeyRealize'
,
err
);
}
}
...
...
@@ -461,8 +457,8 @@ export function getColumnsDataRealize({
ext
=
'xlsx'
,
eliminateRow
=
[],
eliminateCol
=
[],
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
let
content
=
getColumnsData
({
data
,
...
...
@@ -474,8 +470,8 @@ export function getColumnsDataRealize({
ext
,
eliminateRow
,
eliminateCol
,
mergeMappingRow
,
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergeMappingRow
,
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
});
if
(
styles
)
{
content
.
styles
=
styles
;
...
...
@@ -500,12 +496,10 @@ export function getColumnsDataRealize({
ext
,
);
}
catch
(
err
)
{
console
.
table
(
"getColumnsDataRealize"
,
err
);
console
.
table
(
'getColumnsDataRealize'
,
err
);
}
}
/**
*
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
...
...
@@ -574,9 +568,8 @@ export function getCustomDataRealize({
ext
,
);
}
catch
(
err
)
{
console
.
table
(
"getCustomDataRealize"
,
err
);
console
.
table
(
'getCustomDataRealize'
,
err
);
}
}
/**
*
...
...
@@ -606,27 +599,19 @@ export function getColumnsData({
eliminateRow
=
[],
eliminateCol
=
[],
docxSheet
=
{},
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
columns
=
deepCopy
(
columns
);
data
=
deepCopy
(
data
);
let
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
let
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
mergeKey
,
data
,
eliminateRow
,
eliminateCol
,
mergeMappingRow
,
mergePrimaryRow
mergePrimaryRow
,
});
// 处理数据
let
bodyData
=
[];
...
...
@@ -645,13 +630,17 @@ export function getColumnsData({
// 处理合并数据
let
newMergeKey
=
mergeKey
;
try
{
const
newMergeMappingRow
=
Object
.
keys
(
mergeMappingRow
).
filter
(
item1
=>
mergeKey
.
some
(
item2
=>
item2
===
item1
));
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
));
const
mappingList
=
mergeMappingRow
[
item
].
filter
(
(
item1
)
=>
!
mergeKey
.
some
((
item2
)
=>
item2
===
item1
),
);
newMergeKey
=
[...
newMergeKey
,
...
mappingList
];
});
}
catch
(
e
)
{
console
.
table
(
"newMergeKey"
,
e
);
console
.
table
(
'newMergeKey'
,
e
);
}
Object
.
keys
(
rowSpanData
).
forEach
((
mv
)
=>
{
rowSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
...
...
@@ -661,7 +650,7 @@ 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
)
{
...
...
@@ -670,9 +659,9 @@ export function getColumnsData({
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
});
})
});
}
catch
(
err
)
{
console
.
table
(
"getColumnsData"
,
err
);
console
.
table
(
'getColumnsData'
,
err
);
}
let
content
=
{
sheets
:
[
...
...
@@ -682,19 +671,18 @@ export function getColumnsData({
merges
:
[...
columnsMerges
,
...
dataMerges
],
},
],
styles
:
exportStyles
styles
:
exportStyles
,
};
if
(
ext
===
"docx"
)
{
if
(
ext
===
'docx'
)
{
content
.
sheets
[
0
]
=
{
...
content
.
sheets
[
0
],
...
docxSheet
}
...
docxSheet
,
};
}
if
(
styles
)
{
content
.
styles
=
styles
;
}
return
content
return
content
;
}
/**
...
...
@@ -730,14 +718,11 @@ export function getCustomData({
})
{
data
=
deepCopy
(
data
);
let
columnsHeight
=
columnsList
.
length
;
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
mergeKey
,
data
,
eliminateRow
,
eliminateCol
eliminateCol
,
});
// 处理数据
let
bodyData
=
[];
...
...
@@ -771,16 +756,17 @@ export function getCustomData({
});
});
}
catch
(
err
)
{
console
.
table
(
"getCustomData"
,
err
);
console
.
table
(
'getCustomData'
,
err
);
}
const
columnsDataCells
=
[...
columnsList
,
...
bodyData
];
const
columnsDataMerges
=
[...
columnsMerges
,
...
dataMerges
];
let
newBottomMerges
=
[];
if
(
bottomList
&&
bottomList
.
length
>
0
)
{
// 新增底部数据
if
(
bottomList
&&
bottomList
.
length
>
0
)
{
// 新增底部数据
if
(
columnsKey
.
length
!=
bottomList
[
0
].
length
)
{
console
.
table
(
"bottomList数据列数和表头列数不一致"
);
return
console
.
table
(
'bottomList数据列数和表头列数不一致'
);
return
;
}
newBottomMerges
=
bottomMerges
.
map
((
v
,
i
)
=>
{
let
newV
=
v
;
...
...
@@ -799,69 +785,75 @@ export function getCustomData({
merges
:
[...
columnsDataMerges
,
...
newBottomMerges
],
},
],
styles
:
exportStyles
styles
:
exportStyles
,
};
if
(
ext
===
"docx"
)
{
if
(
ext
===
'docx'
)
{
content
.
sheets
[
0
]
=
{
...
content
.
sheets
[
0
],
...
docxSheet
}
...
docxSheet
,
};
}
if
(
styles
)
{
content
.
styles
=
styles
;
}
return
content
return
content
;
}
// ant列表组件合并表格 render属性,合并纵向、横向。
export
function
renderContentAll
(
value
,
row
,
index
,
key
,
spanData
,
cloumnNames
=
[])
{
let
colSpan
,
rowSpan
=
null
;
try
{
colSpan
=
spanData
.
colSpanData
[
key
][
index
];
// 横向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
colSpan
=
spanData
.
colSpanData
[
key
][
index
];
// 横向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
}
catch
(
err
)
{
console
.
table
(
"renderContentAll"
,
err
);
console
.
table
(
'renderContentAll'
,
err
);
}
const
obj
=
{
children
:
value
,
props
:
{
rowSpan
:
rowSpan
,
colSpan
:
colSpan
}
colSpan
:
colSpan
,
},
};
return
obj
;
}
// ant列表组件合并表格 render属性,合并纵向。 meanwhileKey :key 是本身字段key,value 是同步的字段key
export
function
renderContentRow
(
value
,
row
,
index
,
key
,
spanData
,
cloumnNames
=
[],
meanwhileKey
=
{})
{
export
function
renderContentRow
(
value
,
row
,
index
,
key
,
spanData
,
cloumnNames
=
[],
meanwhileKey
=
{},
)
{
let
colSpan
,
rowSpan
=
null
;
try
{
if
(
cloumnNames
.
indexOf
(
key
)
!==
-
1
)
{
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
}
else
{
if
(
key
in
meanwhileKey
&&
meanwhileKey
[
key
])
{
let
meanwhileKeyValue
=
meanwhileKey
[
key
];
rowSpan
=
spanData
.
rowSpanData
[
meanwhileKeyValue
][
index
];
// 同步字段 的纵向合并
rowSpan
=
spanData
.
rowSpanData
[
meanwhileKeyValue
][
index
];
// 同步字段 的纵向合并
}
else
{
rowSpan
=
1
;
}
}
}
catch
(
err
)
{
console
.
table
(
"renderContentRow"
,
err
);
console
.
table
(
'renderContentRow'
,
err
);
}
const
obj
=
{
children
:
value
,
props
:
{
rowSpan
:
rowSpan
,
colSpan
:
1
}
colSpan
:
1
,
},
};
return
obj
;
}
/**
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
...
...
@@ -907,10 +899,8 @@ export function getWord({
}
catch
(
err
)
{
console
.
table
(
err
);
}
}
/**
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
...
...
@@ -957,8 +947,6 @@ export function getFileAndShow({
}
}
/**
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
...
...
@@ -979,7 +967,7 @@ export function getListWord({
listConfig
=
{},
ext
=
'zip'
,
sonExt
=
'pdf'
,
filesKey
=
[]
filesKey
=
[],
})
{
try
{
let
content
=
[];
...
...
@@ -989,10 +977,8 @@ export function getListWord({
for
(
var
ki
in
filesKey
)
{
let
files_
=
v
[
filesKey
[
ki
]];
try
{
files
=
[...
files
,
...
JSON
.
parse
(
files_
).
files
]
}
catch
(
e
)
{
}
files
=
[...
files
,
...
JSON
.
parse
(
files_
).
files
];
}
catch
(
e
)
{}
delete
paramsObj
[
filesKey
[
ki
]];
}
content
.
push
({
...
...
@@ -1001,10 +987,10 @@ export function getListWord({
...
listConfig
,
},
allValues
:
{
...
getObjectsKey
(
allValuesKey
,
paramsObj
)
...
getObjectsKey
(
allValuesKey
,
paramsObj
),
},
title
:
(
paramsObj
[
sonTitleKey
]
||
"未设置名称"
)
+
`.
${
sonExt
}
`
,
files
:
JSON
.
stringify
(
files
)
title
:
(
paramsObj
[
sonTitleKey
]
||
'未设置名称'
)
+
`.
${
sonExt
}
`
,
files
:
JSON
.
stringify
(
files
),
});
});
let
getFileData
=
giveFilePostDataInfoForTrue
(
...
...
@@ -1030,30 +1016,23 @@ export function getListWord({
console
.
table
(
err
);
}
function
getObjectsKey
(
listKey
=
[],
params
=
{})
{
return
(
listKey
.
filter
((
key
)
=>
Object
.
keys
(
params
).
indexOf
(
key
))
.
reduce
(
return
listKey
.
filter
((
key
)
=>
Object
.
keys
(
params
).
indexOf
(
key
)).
reduce
(
(
acc
,
key
)
=>
({
...
acc
,
[
key
]:
params
[
key
]
===
null
?
''
:
params
[
key
],
}),
{},
)
)
);
}
}
export
function
setObjectKey
(
data
)
{
return
(
Object
.
keys
(
data
)
.
reduce
(
return
Object
.
keys
(
data
).
reduce
(
(
acc
,
key
)
=>
({
...
acc
,
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
}),
{},
)
);
}
...
...
@@ -1064,14 +1043,18 @@ export function setObjectKey(data) {
* @param {*} setKey {"被修改的key":"修改后的key"}
* @returns
*/
export
function
upObjKey
(
obj
,
setKey
=
{},
defaultValue
=
""
)
{
export
function
upObjKey
(
obj
,
setKey
=
{},
defaultValue
=
''
)
{
try
{
obj
=
deepCopy
(
obj
);
setKey
=
deepCopy
(
setKey
);
let
objType
=
Object
.
prototype
.
toString
.
call
(
obj
);
if
(
obj
&&
(
objType
.
indexOf
(
"Array"
)
>
-
1
||
objType
.
indexOf
(
"Object"
)
>
-
1
)
&&
Object
.
keys
(
setKey
).
length
>
0
)
{
if
(
obj
&&
(
objType
.
indexOf
(
'Array'
)
>
-
1
||
objType
.
indexOf
(
'Object'
)
>
-
1
)
&&
Object
.
keys
(
setKey
).
length
>
0
)
{
let
nowObj
=
null
;
if
(
objType
===
"[object Object]"
&&
!
Array
.
isArray
(
obj
)
&&
Object
.
keys
(
obj
).
length
>
0
)
{
if
(
objType
===
'[object Object]'
&&
!
Array
.
isArray
(
obj
)
&&
Object
.
keys
(
obj
).
length
>
0
)
{
nowObj
=
deepCopy
(
obj
);
for
(
var
e
in
setKey
)
{
let
upKey
=
setKey
[
e
];
...
...
@@ -1079,15 +1062,20 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
nowObj
=
{
...
nowObj
,
...
getSetKeyJson
({
obj
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
})
obj
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
,
}),
};
if
(
e
!=
newKey
)
{
delete
nowObj
[
e
];
}
}
}
if
(
objType
===
"[object Array]"
&&
Array
.
isArray
(
obj
)
&&
obj
.
length
>
0
)
{
if
(
objType
===
'[object Array]'
&&
Array
.
isArray
(
obj
)
&&
obj
.
length
>
0
)
{
nowObj
=
new
Array
();
obj
.
forEach
((
v
,
i
,
arr
)
=>
{
let
newJson
=
deepCopy
(
v
);
...
...
@@ -1097,22 +1085,27 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
newJson
=
{
...
newJson
,
...
getSetKeyJson
({
obj
:
v
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
})
obj
:
v
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
,
}),
};
if
(
e
!=
newKey
)
{
delete
newJson
[
e
];
}
}
nowObj
.
push
(
newJson
);
})
});
}
return
nowObj
;
}
else
{
return
null
;
}
}
catch
(
error
)
{
console
.
table
(
"upObjKey"
,
error
);
console
.
table
(
'upObjKey'
,
error
);
return
undefined
;
}
}
...
...
@@ -1121,40 +1114,39 @@ function getSetKeyValue(value) {
let
valeuType
=
Object
.
prototype
.
toString
.
call
(
value
);
let
newName
=
null
;
let
extendJson
=
{
"type"
:
"string"
type
:
'string'
,
};
if
(
valeuType
===
"[object String]"
)
{
if
(
valeuType
===
'[object String]'
)
{
newName
=
value
;
}
if
(
valeuType
===
"[object Object]"
)
{
newName
=
value
[
"new"
];
delete
value
[
"new"
];
if
(
valeuType
===
'[object Object]'
)
{
newName
=
value
[
'new'
];
delete
value
[
'new'
];
extendJson
=
{
...
extendJson
,
...
value
...
value
,
};
}
return
{
newKey
:
newName
,
...
extendJson
}
...
extendJson
,
};
}
function
getSetKeyJson
({
obj
,
e
,
newKey
,
type
,
timeFormat
=
"YYYY-MM-DD HH:mm:ss"
,
defaultValue
})
{
function
getSetKeyJson
({
obj
,
e
,
newKey
,
type
,
timeFormat
=
'YYYY-MM-DD HH:mm:ss'
,
defaultValue
})
{
obj
=
deepCopy
(
obj
);
let
value
=
obj
[
e
];
let
newKeyObj
=
{};
// delete obj[e];
switch
(
type
)
{
case
"time"
:
newKeyObj
[
newKey
]
=
(
timeFormat
&&
value
?
moment
(
value
).
format
(
timeFormat
)
:
value
)
||
defaultValue
;
case
'time'
:
newKeyObj
[
newKey
]
=
(
timeFormat
&&
value
?
moment
(
value
).
format
(
timeFormat
)
:
value
)
||
defaultValue
;
break
;
case
"flow"
:
case
'flow'
:
newKeyObj
[
newKey
]
=
{
"code"
:
value
||
defaultValue
,
"type"
:
"flow"
code
:
value
||
defaultValue
,
type
:
'flow'
,
};
break
;
default
:
...
...
@@ -1163,7 +1155,6 @@ function getSetKeyJson({
return
newKeyObj
;
}
// 下载附件FormdataWrapper
function
isObject
(
value
)
{
return
value
===
Object
(
value
);
...
...
@@ -1183,13 +1174,12 @@ function makeArrayKey(key) {
export
function
FormdataWrapper
(
obj
,
fd
,
pre
)
{
fd
=
fd
||
new
FormData
();
Object
.
keys
(
obj
)
.
forEach
(
function
(
prop
)
{
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
)
{
obj
[
prop
].
forEach
(
function
(
value
)
{
var
arrayKey
=
makeArrayKey
(
key
);
if
(
isObject
(
value
)
&&
!
isFile
(
value
))
{
FormdataWrapper
(
value
,
fd
,
arrayKey
);
...
...
@@ -1204,7 +1194,6 @@ export function FormdataWrapper(obj, fd, pre) {
return
fd
;
}
// TODO http://scjoyedu.eicp.net:57400/zentao/task-view-4023.html 等生产环境更新后测试.
// http://xg.qnzy.net:51352/zyd/#/xg/student_affairs/MI/UrbanAndRuralMedicalInsurance/InsuredPersonnel
export
async
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
...
...
@@ -1218,10 +1207,15 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
body
:
FormdataWrapper
(
params
),
headers
,
})
.
then
(
(
res
)
=>
{
.
then
(
async
(
res
)
=>
{
if
(
res
.
status
+
''
!==
'200'
)
{
return
res
.
json
();
}
else
{
if
(
params
&&
params
.
showDownloadProgressFromFileName
)
{
// 2024年11月4日 解决禅道
showDownloadProgressFromFileName
(
res
,
{
ext
,
fileName
});
return
true
;
}
return
res
.
blob
();
}
})
...
...
@@ -1236,7 +1230,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
a
.
click
();
window
.
URL
.
revokeObjectURL
(
url
);
a
=
null
;
}
else
{
}
})
.
catch
((
err
)
=>
{
...
...
@@ -1247,7 +1240,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
});
}
export
async
function
downloadFileAndShowModal
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
const
{
transformApi
,
headersApi
}
=
await
getTransformApi
(
url
);
let
headers
=
getSassApiHeader
();
...
...
@@ -1278,17 +1270,20 @@ export async function downloadFileAndShowModal(url, params, fileName = '导出
Modal
.
info
({
title
:
filename
,
width
:
1000
,
content
:
<
div
>
<
embed
width
=
'100%'
height
=
'568px'
name
=
'plugin'
id
=
'pdfView'
content
:
(
<
div
>
<
embed
width
=
"100%"
height
=
"568px"
name
=
"plugin"
id
=
"pdfView"
src
=
{
url
}
type
=
'application/pdf'
internalinstanceid
=
'3'
title
=
{
filename
}
/
>
<
/div>
,
type
=
"application/pdf"
internalinstanceid
=
"3"
title
=
{
filename
}
/
>
<
/div
>
),
okText
:
'确定'
,
onCancel
:
()
=>
{
window
.
URL
.
revokeObjectURL
(
url
);
...
...
one_stop_public/Table/utils.js
0 → 100644
浏览文件 @
cfc0faf3
import
React
from
'react'
;
import
{
Modal
,
message
,
Progress
}
from
'antd'
;
export
async
function
showDownloadProgressFromFileName
(
res
,
{
ext
,
fileName
})
{
const
reader
=
res
.
body
.
getReader
();
let
contentLength
=
res
.
headers
.
get
(
'Content-Disposition'
).
split
(
'filename='
)[
1
];
// 文件大小从filename里面取
let
nowTime
=
new
Date
().
getTime
();
if
(
contentLength
&&
contentLength
.
includes
(
'.'
))
{
contentLength
=
Number
(
contentLength
.
split
(
'.'
)[
0
]);
// 文件大小
if
(
contentLength
>
0
)
{
message
.
info
(
'正在获取文件,请耐心等待'
);
let
receivedLength
=
0
;
let
chunks
=
[];
while
(
true
)
{
const
{
done
,
value
}
=
await
reader
.
read
();
if
(
done
)
{
break
;
}
chunks
.
push
(
value
);
receivedLength
+=
value
.
length
;
// 下载进度
const
progress
=
(
receivedLength
/
contentLength
)
*
100
;
if
(
new
Date
().
getTime
()
-
1200
>
nowTime
)
{
message
.
info
(
'正在获取文件,请耐心等待,下载进度为'
+
progress
.
toFixed
(
2
)
+
'%'
,
1
);
nowTime
=
new
Date
().
getTime
();
}
// 将获取的百分比callback返回出去
// console.log(progress);
// console.log(`Reveived ${receivedLength} of ${contentLength}`, progress, 'progress');
}
let
a
=
document
.
createElement
(
'a'
);
a
.
style
.
display
=
'none'
;
document
.
body
.
append
(
a
);
const
urlFile
=
window
.
URL
.
createObjectURL
(
new
Blob
(
chunks
,
{
type
:
ext
}));
a
.
href
=
urlFile
;
let
filename
=
fileName
;
if
(
ext
&&
filename
.
indexOf
(
'.'
)
===
-
1
)
{
filename
=
filename
+
'.'
+
ext
;
}
a
.
download
=
filename
;
a
.
click
();
document
.
body
.
removeChild
(
a
);
window
.
URL
.
revokeObjectURL
(
urlFile
);
a
=
null
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论