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';
...
@@ -5,9 +5,8 @@ import { getToken } from '@/webPublic/one_stop_public/utils/token';
import
{
deepCopy
}
from
'@/webPublic/zyd_public/utils/utils'
;
import
{
deepCopy
}
from
'@/webPublic/zyd_public/utils/utils'
;
import
{
getTransformApi
}
from
'@/webPublic/one_stop_public/2022beidianke/localstorageTransform'
;
import
{
getTransformApi
}
from
'@/webPublic/one_stop_public/2022beidianke/localstorageTransform'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
{
import
{
getSassApiHeader
}
from
'@/webPublic/one_stop_public/2023yunshangguizhou/utils'
;
getSassApiHeader
,
import
{
showDownloadProgressFromFileName
}
from
"./utils"
;
}
from
'@/webPublic/one_stop_public/2023yunshangguizhou/utils'
;
const
apiUrl
=
queryOauthActionPath
();
const
apiUrl
=
queryOauthActionPath
();
export
{
apiUrl
};
export
{
apiUrl
};
...
@@ -39,7 +38,7 @@ const uj = {
...
@@ -39,7 +38,7 @@ const uj = {
t
:
1
,
t
:
1
,
v
:
'序号'
,
v
:
'序号'
,
s
:
'header'
,
s
:
'header'
,
w
:
20
//默认值是20像素
w
:
20
,
//默认值是20像素
};
};
/**
/**
* 公共函数代码
* 公共函数代码
...
@@ -62,31 +61,35 @@ export function getSpanJson({
...
@@ -62,31 +61,35 @@ export function getSpanJson({
eliminateRow
=
[],
eliminateRow
=
[],
eliminateCol
=
[],
eliminateCol
=
[],
mergePrimaryRow
,
mergePrimaryRow
,
mergeMappingRow
=
{}
// 某一列的合并数据 复制 到任意其他列
mergeMappingRow
=
{},
// 某一列的合并数据 复制 到任意其他列
})
{
})
{
const
dataList
=
deepCopy
(
data
);
const
dataList
=
deepCopy
(
data
);
let
rowSpanData
,
colSpanData
=
null
;
let
rowSpanData
,
colSpanData
=
null
;
try
{
try
{
rowSpanData
=
getRowSpanJson
(
mergeKey
,
dataList
,
eliminateRow
,
mergePrimaryRow
);
rowSpanData
=
getRowSpanJson
(
mergeKey
,
dataList
,
eliminateRow
,
mergePrimaryRow
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"rowSpanData"
,
err
);
console
.
table
(
'rowSpanData'
,
err
);
}
}
try
{
try
{
colSpanData
=
getColSpanJson
(
mergeKey
,
dataList
,
eliminateCol
);
colSpanData
=
getColSpanJson
(
mergeKey
,
dataList
,
eliminateCol
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"colSpanData"
,
err
);
console
.
table
(
'colSpanData'
,
err
);
}
}
try
{
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
)
=>
{
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
)
=>
{
mappingList
.
map
((
mItem
)
=>
{
rowSpanData
[
mItem
]
=
rowSpanData
[
item
];
rowSpanData
[
mItem
]
=
rowSpanData
[
item
];
});
});
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
table
(
"mergeMappingRow"
,
e
);
console
.
table
(
'mergeMappingRow'
,
e
);
}
}
return
{
return
{
rowSpanData
,
rowSpanData
,
...
@@ -107,16 +110,18 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
...
@@ -107,16 +110,18 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
var
startIndexMap
=
{};
var
startIndexMap
=
{};
// 是否主键模式
// 是否主键模式
var
isPrimary
=
false
;
var
isPrimary
=
false
;
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 循环数据
for
(
var
idx
=
0
;
idx
<
data
.
length
;
idx
++
)
{
// 循环数据
var
dataItem
=
data
[
idx
];
var
dataItem
=
data
[
idx
];
var
dataItemRowValue
;
var
dataItemRowValue
;
var
dataItemPreviousRowValue
;
var
dataItemPreviousRowValue
;
if
(
mergePrimaryRow
)
{
if
(
mergePrimaryRow
)
{
isPrimary
=
true
;
//开启主键模式
isPrimary
=
true
;
//开启主键模式
dataItemRowValue
=
dataItem
[
mergePrimaryRow
];
dataItemRowValue
=
dataItem
[
mergePrimaryRow
];
dataItemPreviousRowValue
=
data
[
idx
-
1
>
0
?
idx
-
1
:
0
][
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
keyItem
=
cloumnNames
[
idj
];
var
dataItemValue
=
dataItem
[
keyItem
];
var
dataItemValue
=
dataItem
[
keyItem
];
if
(
idx
===
0
)
{
if
(
idx
===
0
)
{
...
@@ -128,8 +133,11 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
...
@@ -128,8 +133,11 @@ function getRowSpanJson(cloumnNames, data, eliminateStr = [], mergePrimaryRow) {
continue
;
continue
;
}
}
if
(
if
(
(
!
isPrimary
?
(
dataItemValue
===
beforeNameMap
[
keyItem
])
:
(
dataItemRowValue
+
dataItemValue
===
dataItemPreviousRowValue
+
beforeNameMap
[
keyItem
]))
// 与上一个值一致时
(
!
isPrimary
&&
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
// 排除特定的值合并
?
dataItemValue
===
beforeNameMap
[
keyItem
]
:
dataItemRowValue
+
dataItemValue
===
dataItemPreviousRowValue
+
beforeNameMap
[
keyItem
])
&&
// 与上一个值一致时
eliminateStr
.
indexOf
(
dataItemValue
)
===
-
1
// 排除特定的值合并
)
{
)
{
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
countMap
[
keyItem
]
=
countMap
[
keyItem
]
+
1
;
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
rowSpanJson
[
keyItem
][
startIndexMap
[
keyItem
]]
=
countMap
[
keyItem
];
...
@@ -239,7 +247,7 @@ export function getColumns(columns) {
...
@@ -239,7 +247,7 @@ export function getColumns(columns) {
}
}
return
res
;
return
res
;
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
table
(
"getColumnsDatas"
,
e
);
console
.
table
(
'getColumnsDatas'
,
e
);
return
[];
return
[];
}
}
}
}
...
@@ -264,7 +272,6 @@ export function getColumns(columns) {
...
@@ -264,7 +272,6 @@ export function getColumns(columns) {
return
maxLevel
;
return
maxLevel
;
}
}
//递归当前数据宽度
//递归当前数据宽度
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
function
getColumnsWidth
(
data
=
[],
sum
=
0
)
{
for
(
let
item
of
data
)
{
for
(
let
item
of
data
)
{
...
@@ -277,18 +284,12 @@ export function getColumns(columns) {
...
@@ -277,18 +284,12 @@ export function getColumns(columns) {
return
sum
;
return
sum
;
}
}
let
columnsHandle
=
getColumnsDatas
(
columns
)
let
columnsHandle
=
getColumnsDatas
(
columns
).
filter
((
v
,
i
)
=>
{
.
filter
((
v
,
i
)
=>
{
return
(
v
.
level
<
columnsHeight
&&
v
.
isLast
)
||
v
.
width
>
1
;
return
(
v
.
level
<
columnsHeight
&&
v
.
isLast
)
||
v
.
width
>
1
;
});
});
let
columnsMerges
=
[];
let
columnsMerges
=
[];
columnsHandle
.
forEach
((
v
,
i
)
=>
{
columnsHandle
.
forEach
((
v
,
i
)
=>
{
let
{
let
{
isLast
,
width
,
col
,
level
}
=
v
;
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
)
{
...
@@ -324,15 +325,11 @@ export function getColumnsSqlKeyRealize({
...
@@ -324,15 +325,11 @@ export function getColumnsSqlKeyRealize({
styles
,
styles
,
fileName
=
'导出文件'
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
ext
=
'xlsx'
,
allValues
=
JSON
.
stringify
({})
allValues
=
JSON
.
stringify
({}),
})
{
})
{
columns
=
deepCopy
(
columns
);
columns
=
deepCopy
(
columns
);
let
{
let
{
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
columnsList
,
columnsMerges
,
columnsKey
}
=
getColumns
(
columns
);
let
content
=
{
let
content
=
{
sheets
:
[
sheets
:
[
...
@@ -344,7 +341,7 @@ export function getColumnsSqlKeyRealize({
...
@@ -344,7 +341,7 @@ export function getColumnsSqlKeyRealize({
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
},
],
],
styles
:
exportStyles
styles
:
exportStyles
,
};
};
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
...
@@ -354,7 +351,7 @@ export function getColumnsSqlKeyRealize({
...
@@ -354,7 +351,7 @@ export function getColumnsSqlKeyRealize({
{
{
content
:
JSON
.
stringify
(
content
),
content
:
JSON
.
stringify
(
content
),
title
:
fileName
,
title
:
fileName
,
allValues
:
allValues
allValues
:
allValues
,
},
},
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
);
);
...
@@ -369,11 +366,10 @@ export function getColumnsSqlKeyRealize({
...
@@ -369,11 +366,10 @@ export function getColumnsSqlKeyRealize({
ext
,
ext
,
);
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getColumnsSqlKeyRealize"
,
err
);
console
.
table
(
'getColumnsSqlKeyRealize'
,
err
);
}
}
}
}
/**
/**
*
*
* @param {sqlKey,columnsList,columnsMerges,columnsKey,styles,fileName,ext,allValues} param
* @param {sqlKey,columnsList,columnsMerges,columnsKey,styles,fileName,ext,allValues} param
...
@@ -395,7 +391,7 @@ export function getCustomSqlKeyRealize({
...
@@ -395,7 +391,7 @@ export function getCustomSqlKeyRealize({
styles
,
styles
,
fileName
=
'导出文件'
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
,
ext
=
'xlsx'
,
allValues
=
JSON
.
stringify
({})
allValues
=
JSON
.
stringify
({}),
})
{
})
{
let
content
=
{
let
content
=
{
sheets
:
[
sheets
:
[
...
@@ -407,7 +403,7 @@ export function getCustomSqlKeyRealize({
...
@@ -407,7 +403,7 @@ export function getCustomSqlKeyRealize({
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
sqlKeyHeader
:
columnsKey
,
//sql对应key对应列
},
},
],
],
styles
:
exportStyles
styles
:
exportStyles
,
};
};
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
...
@@ -417,7 +413,7 @@ export function getCustomSqlKeyRealize({
...
@@ -417,7 +413,7 @@ export function getCustomSqlKeyRealize({
{
{
content
:
JSON
.
stringify
(
content
),
content
:
JSON
.
stringify
(
content
),
title
:
fileName
,
title
:
fileName
,
allValues
:
allValues
allValues
:
allValues
,
},
},
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
`
${
apiUrl
+
'/DataObjApi/exportCustom'
}
`
,
);
);
...
@@ -432,7 +428,7 @@ export function getCustomSqlKeyRealize({
...
@@ -432,7 +428,7 @@ export function getCustomSqlKeyRealize({
ext
,
ext
,
);
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getCustomSqlKeyRealize"
,
err
);
console
.
table
(
'getCustomSqlKeyRealize'
,
err
);
}
}
}
}
...
@@ -461,8 +457,8 @@ export function getColumnsDataRealize({
...
@@ -461,8 +457,8 @@ export function getColumnsDataRealize({
ext
=
'xlsx'
,
ext
=
'xlsx'
,
eliminateRow
=
[],
eliminateRow
=
[],
eliminateCol
=
[],
eliminateCol
=
[],
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
})
{
let
content
=
getColumnsData
({
let
content
=
getColumnsData
({
data
,
data
,
...
@@ -474,8 +470,8 @@ export function getColumnsDataRealize({
...
@@ -474,8 +470,8 @@ export function getColumnsDataRealize({
ext
,
ext
,
eliminateRow
,
eliminateRow
,
eliminateCol
,
eliminateCol
,
mergeMappingRow
,
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergeMappingRow
,
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
});
});
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
...
@@ -500,12 +496,10 @@ export function getColumnsDataRealize({
...
@@ -500,12 +496,10 @@ export function getColumnsDataRealize({
ext
,
ext
,
);
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getColumnsDataRealize"
,
err
);
console
.
table
(
'getColumnsDataRealize'
,
err
);
}
}
}
}
/**
/**
*
*
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
* @param {data,columns,styles,defect,fileName,ext,url,eliminateRow,eliminateCol} param
...
@@ -574,9 +568,8 @@ export function getCustomDataRealize({
...
@@ -574,9 +568,8 @@ export function getCustomDataRealize({
ext
,
ext
,
);
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getCustomDataRealize"
,
err
);
console
.
table
(
'getCustomDataRealize'
,
err
);
}
}
}
}
/**
/**
*
*
...
@@ -606,27 +599,19 @@ export function getColumnsData({
...
@@ -606,27 +599,19 @@ export function getColumnsData({
eliminateRow
=
[],
eliminateRow
=
[],
eliminateCol
=
[],
eliminateCol
=
[],
docxSheet
=
{},
docxSheet
=
{},
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergeMappingRow
=
{},
// *映射mergeKey 纵向合并结果,key必须在mergeKey数组里面
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
mergePrimaryRow
,
// 所有合并都会在当前mergePrimary 的范围下合并
})
{
})
{
columns
=
deepCopy
(
columns
);
columns
=
deepCopy
(
columns
);
data
=
deepCopy
(
data
);
data
=
deepCopy
(
data
);
let
{
let
{
columnsList
,
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
columnsList
,
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
columnsMerges
,
columnsKey
,
columnsHeight
}
=
getColumns
(
columns
);
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
mergeKey
,
mergeKey
,
data
,
data
,
eliminateRow
,
eliminateRow
,
eliminateCol
,
eliminateCol
,
mergeMappingRow
,
mergeMappingRow
,
mergePrimaryRow
mergePrimaryRow
,
});
});
// 处理数据
// 处理数据
let
bodyData
=
[];
let
bodyData
=
[];
...
@@ -645,13 +630,17 @@ export function getColumnsData({
...
@@ -645,13 +630,17 @@ export function getColumnsData({
// 处理合并数据
// 处理合并数据
let
newMergeKey
=
mergeKey
;
let
newMergeKey
=
mergeKey
;
try
{
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
)
=>
{
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
];
newMergeKey
=
[...
newMergeKey
,
...
mappingList
];
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
table
(
"newMergeKey"
,
e
);
console
.
table
(
'newMergeKey'
,
e
);
}
}
Object
.
keys
(
rowSpanData
).
forEach
((
mv
)
=>
{
Object
.
keys
(
rowSpanData
).
forEach
((
mv
)
=>
{
rowSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
rowSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
...
@@ -661,7 +650,7 @@ export function getColumnsData({
...
@@ -661,7 +650,7 @@ export function getColumnsData({
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
+
cv
-
1
,
rowIndex
,
rowIndex
]);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
+
cv
-
1
,
rowIndex
,
rowIndex
]);
}
}
});
});
})
});
Object
.
keys
(
colSpanData
).
forEach
((
mv
)
=>
{
Object
.
keys
(
colSpanData
).
forEach
((
mv
)
=>
{
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
colSpanData
[
mv
].
forEach
((
cv
,
ci
)
=>
{
if
(
cv
>
1
)
{
if
(
cv
>
1
)
{
...
@@ -670,9 +659,9 @@ export function getColumnsData({
...
@@ -670,9 +659,9 @@ export function getColumnsData({
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
dataMerges
.
push
([
columnsHeight
+
ci
,
columnsHeight
+
ci
,
rowIndex
,
rowIndex
+
cv
-
1
]);
}
}
});
});
})
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getColumnsData"
,
err
);
console
.
table
(
'getColumnsData'
,
err
);
}
}
let
content
=
{
let
content
=
{
sheets
:
[
sheets
:
[
...
@@ -682,19 +671,18 @@ export function getColumnsData({
...
@@ -682,19 +671,18 @@ export function getColumnsData({
merges
:
[...
columnsMerges
,
...
dataMerges
],
merges
:
[...
columnsMerges
,
...
dataMerges
],
},
},
],
],
styles
:
exportStyles
styles
:
exportStyles
,
};
};
if
(
ext
===
"docx"
)
{
if
(
ext
===
'docx'
)
{
content
.
sheets
[
0
]
=
{
content
.
sheets
[
0
]
=
{
...
content
.
sheets
[
0
],
...
content
.
sheets
[
0
],
...
docxSheet
...
docxSheet
,
}
};
}
}
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
}
}
return
content
return
content
;
}
}
/**
/**
...
@@ -730,14 +718,11 @@ export function getCustomData({
...
@@ -730,14 +718,11 @@ export function getCustomData({
})
{
})
{
data
=
deepCopy
(
data
);
data
=
deepCopy
(
data
);
let
columnsHeight
=
columnsList
.
length
;
let
columnsHeight
=
columnsList
.
length
;
let
{
let
{
colSpanData
,
rowSpanData
}
=
getSpanJson
({
colSpanData
,
rowSpanData
}
=
getSpanJson
({
mergeKey
,
mergeKey
,
data
,
data
,
eliminateRow
,
eliminateRow
,
eliminateCol
eliminateCol
,
});
});
// 处理数据
// 处理数据
let
bodyData
=
[];
let
bodyData
=
[];
...
@@ -771,16 +756,17 @@ export function getCustomData({
...
@@ -771,16 +756,17 @@ export function getCustomData({
});
});
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"getCustomData"
,
err
);
console
.
table
(
'getCustomData'
,
err
);
}
}
const
columnsDataCells
=
[...
columnsList
,
...
bodyData
];
const
columnsDataCells
=
[...
columnsList
,
...
bodyData
];
const
columnsDataMerges
=
[...
columnsMerges
,
...
dataMerges
];
const
columnsDataMerges
=
[...
columnsMerges
,
...
dataMerges
];
let
newBottomMerges
=
[];
let
newBottomMerges
=
[];
if
(
bottomList
&&
bottomList
.
length
>
0
)
{
// 新增底部数据
if
(
bottomList
&&
bottomList
.
length
>
0
)
{
// 新增底部数据
if
(
columnsKey
.
length
!=
bottomList
[
0
].
length
)
{
if
(
columnsKey
.
length
!=
bottomList
[
0
].
length
)
{
console
.
table
(
"bottomList数据列数和表头列数不一致"
);
console
.
table
(
'bottomList数据列数和表头列数不一致'
);
return
return
;
}
}
newBottomMerges
=
bottomMerges
.
map
((
v
,
i
)
=>
{
newBottomMerges
=
bottomMerges
.
map
((
v
,
i
)
=>
{
let
newV
=
v
;
let
newV
=
v
;
...
@@ -799,69 +785,75 @@ export function getCustomData({
...
@@ -799,69 +785,75 @@ export function getCustomData({
merges
:
[...
columnsDataMerges
,
...
newBottomMerges
],
merges
:
[...
columnsDataMerges
,
...
newBottomMerges
],
},
},
],
],
styles
:
exportStyles
styles
:
exportStyles
,
};
};
if
(
ext
===
"docx"
)
{
if
(
ext
===
'docx'
)
{
content
.
sheets
[
0
]
=
{
content
.
sheets
[
0
]
=
{
...
content
.
sheets
[
0
],
...
content
.
sheets
[
0
],
...
docxSheet
...
docxSheet
,
}
};
}
}
if
(
styles
)
{
if
(
styles
)
{
content
.
styles
=
styles
;
content
.
styles
=
styles
;
}
}
return
content
return
content
;
}
}
// ant列表组件合并表格 render属性,合并纵向、横向。
// ant列表组件合并表格 render属性,合并纵向、横向。
export
function
renderContentAll
(
value
,
row
,
index
,
key
,
spanData
,
cloumnNames
=
[])
{
export
function
renderContentAll
(
value
,
row
,
index
,
key
,
spanData
,
cloumnNames
=
[])
{
let
colSpan
,
let
colSpan
,
rowSpan
=
null
;
rowSpan
=
null
;
try
{
try
{
colSpan
=
spanData
.
colSpanData
[
key
][
index
];
// 横向合并
colSpan
=
spanData
.
colSpanData
[
key
][
index
];
// 横向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"renderContentAll"
,
err
);
console
.
table
(
'renderContentAll'
,
err
);
}
}
const
obj
=
{
const
obj
=
{
children
:
value
,
children
:
value
,
props
:
{
props
:
{
rowSpan
:
rowSpan
,
rowSpan
:
rowSpan
,
colSpan
:
colSpan
colSpan
:
colSpan
,
}
},
};
};
return
obj
;
return
obj
;
}
}
// ant列表组件合并表格 render属性,合并纵向。 meanwhileKey :key 是本身字段key,value 是同步的字段key
// 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
,
let
colSpan
,
rowSpan
=
null
;
rowSpan
=
null
;
try
{
try
{
if
(
cloumnNames
.
indexOf
(
key
)
!==
-
1
)
{
if
(
cloumnNames
.
indexOf
(
key
)
!==
-
1
)
{
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
rowSpan
=
spanData
.
rowSpanData
[
key
][
index
];
// 纵向合并
}
else
{
}
else
{
if
(
key
in
meanwhileKey
&&
meanwhileKey
[
key
])
{
if
(
key
in
meanwhileKey
&&
meanwhileKey
[
key
])
{
let
meanwhileKeyValue
=
meanwhileKey
[
key
];
let
meanwhileKeyValue
=
meanwhileKey
[
key
];
rowSpan
=
spanData
.
rowSpanData
[
meanwhileKeyValue
][
index
];
// 同步字段 的纵向合并
rowSpan
=
spanData
.
rowSpanData
[
meanwhileKeyValue
][
index
];
// 同步字段 的纵向合并
}
else
{
}
else
{
rowSpan
=
1
;
rowSpan
=
1
;
}
}
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
"renderContentRow"
,
err
);
console
.
table
(
'renderContentRow'
,
err
);
}
}
const
obj
=
{
const
obj
=
{
children
:
value
,
children
:
value
,
props
:
{
props
:
{
rowSpan
:
rowSpan
,
rowSpan
:
rowSpan
,
colSpan
:
1
colSpan
:
1
,
}
},
};
};
return
obj
;
return
obj
;
}
}
/**
/**
* 表头和数据导出(合并表格)
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
* templatePath : word文档模板地址
...
@@ -907,10 +899,8 @@ export function getWord({
...
@@ -907,10 +899,8 @@ export function getWord({
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
table
(
err
);
console
.
table
(
err
);
}
}
}
}
/**
/**
* 表头和数据导出(合并表格)
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
* templatePath : word文档模板地址
...
@@ -957,8 +947,6 @@ export function getFileAndShow({
...
@@ -957,8 +947,6 @@ export function getFileAndShow({
}
}
}
}
/**
/**
* 表头和数据导出(合并表格)
* 表头和数据导出(合并表格)
* templatePath : word文档模板地址
* templatePath : word文档模板地址
...
@@ -979,7 +967,7 @@ export function getListWord({
...
@@ -979,7 +967,7 @@ export function getListWord({
listConfig
=
{},
listConfig
=
{},
ext
=
'zip'
,
ext
=
'zip'
,
sonExt
=
'pdf'
,
sonExt
=
'pdf'
,
filesKey
=
[]
filesKey
=
[],
})
{
})
{
try
{
try
{
let
content
=
[];
let
content
=
[];
...
@@ -989,10 +977,8 @@ export function getListWord({
...
@@ -989,10 +977,8 @@ export function getListWord({
for
(
var
ki
in
filesKey
)
{
for
(
var
ki
in
filesKey
)
{
let
files_
=
v
[
filesKey
[
ki
]];
let
files_
=
v
[
filesKey
[
ki
]];
try
{
try
{
files
=
[...
files
,
...
JSON
.
parse
(
files_
).
files
]
files
=
[...
files
,
...
JSON
.
parse
(
files_
).
files
];
}
catch
(
e
)
{
}
catch
(
e
)
{}
}
delete
paramsObj
[
filesKey
[
ki
]];
delete
paramsObj
[
filesKey
[
ki
]];
}
}
content
.
push
({
content
.
push
({
...
@@ -1001,10 +987,10 @@ export function getListWord({
...
@@ -1001,10 +987,10 @@ export function getListWord({
...
listConfig
,
...
listConfig
,
},
},
allValues
:
{
allValues
:
{
...
getObjectsKey
(
allValuesKey
,
paramsObj
)
...
getObjectsKey
(
allValuesKey
,
paramsObj
),
},
},
title
:
(
paramsObj
[
sonTitleKey
]
||
"未设置名称"
)
+
`.
${
sonExt
}
`
,
title
:
(
paramsObj
[
sonTitleKey
]
||
'未设置名称'
)
+
`.
${
sonExt
}
`
,
files
:
JSON
.
stringify
(
files
)
files
:
JSON
.
stringify
(
files
),
});
});
});
});
let
getFileData
=
giveFilePostDataInfoForTrue
(
let
getFileData
=
giveFilePostDataInfoForTrue
(
...
@@ -1030,30 +1016,23 @@ export function getListWord({
...
@@ -1030,30 +1016,23 @@ export function getListWord({
console
.
table
(
err
);
console
.
table
(
err
);
}
}
function
getObjectsKey
(
listKey
=
[],
params
=
{})
{
function
getObjectsKey
(
listKey
=
[],
params
=
{})
{
return
(
return
listKey
.
filter
((
key
)
=>
Object
.
keys
(
params
).
indexOf
(
key
)).
reduce
(
listKey
.
filter
((
key
)
=>
Object
.
keys
(
params
).
indexOf
(
key
))
.
reduce
(
(
acc
,
key
)
=>
({
(
acc
,
key
)
=>
({
...
acc
,
...
acc
,
[
key
]:
params
[
key
]
===
null
?
''
:
params
[
key
],
[
key
]:
params
[
key
]
===
null
?
''
:
params
[
key
],
}),
}),
{},
{},
)
);
)
}
}
}
}
export
function
setObjectKey
(
data
)
{
export
function
setObjectKey
(
data
)
{
return
(
return
Object
.
keys
(
data
).
reduce
(
Object
.
keys
(
data
)
.
reduce
(
(
acc
,
key
)
=>
({
(
acc
,
key
)
=>
({
...
acc
,
...
acc
,
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
[
'${'
+
key
+
'}'
]:
data
[
key
]
===
null
?
''
:
data
[
key
],
}),
}),
{},
{},
)
);
);
}
}
...
@@ -1064,14 +1043,18 @@ export function setObjectKey(data) {
...
@@ -1064,14 +1043,18 @@ export function setObjectKey(data) {
* @param {*} setKey {"被修改的key":"修改后的key"}
* @param {*} setKey {"被修改的key":"修改后的key"}
* @returns
* @returns
*/
*/
export
function
upObjKey
(
obj
,
setKey
=
{},
defaultValue
=
""
)
{
export
function
upObjKey
(
obj
,
setKey
=
{},
defaultValue
=
''
)
{
try
{
try
{
obj
=
deepCopy
(
obj
);
obj
=
deepCopy
(
obj
);
setKey
=
deepCopy
(
setKey
);
setKey
=
deepCopy
(
setKey
);
let
objType
=
Object
.
prototype
.
toString
.
call
(
obj
);
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
;
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
);
nowObj
=
deepCopy
(
obj
);
for
(
var
e
in
setKey
)
{
for
(
var
e
in
setKey
)
{
let
upKey
=
setKey
[
e
];
let
upKey
=
setKey
[
e
];
...
@@ -1079,15 +1062,20 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
...
@@ -1079,15 +1062,20 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
nowObj
=
{
nowObj
=
{
...
nowObj
,
...
nowObj
,
...
getSetKeyJson
({
...
getSetKeyJson
({
obj
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
obj
,
})
e
,
newKey
,
type
,
timeFormat
,
defaultValue
,
}),
};
};
if
(
e
!=
newKey
)
{
if
(
e
!=
newKey
)
{
delete
nowObj
[
e
];
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
();
nowObj
=
new
Array
();
obj
.
forEach
((
v
,
i
,
arr
)
=>
{
obj
.
forEach
((
v
,
i
,
arr
)
=>
{
let
newJson
=
deepCopy
(
v
);
let
newJson
=
deepCopy
(
v
);
...
@@ -1097,22 +1085,27 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
...
@@ -1097,22 +1085,27 @@ export function upObjKey(obj, setKey = {}, defaultValue = "") {
newJson
=
{
newJson
=
{
...
newJson
,
...
newJson
,
...
getSetKeyJson
({
...
getSetKeyJson
({
obj
:
v
,
e
,
newKey
,
type
,
timeFormat
,
defaultValue
obj
:
v
,
})
e
,
newKey
,
type
,
timeFormat
,
defaultValue
,
}),
};
};
if
(
e
!=
newKey
)
{
if
(
e
!=
newKey
)
{
delete
newJson
[
e
];
delete
newJson
[
e
];
}
}
}
}
nowObj
.
push
(
newJson
);
nowObj
.
push
(
newJson
);
})
});
}
}
return
nowObj
;
return
nowObj
;
}
else
{
}
else
{
return
null
;
return
null
;
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
table
(
"upObjKey"
,
error
);
console
.
table
(
'upObjKey'
,
error
);
return
undefined
;
return
undefined
;
}
}
}
}
...
@@ -1121,40 +1114,39 @@ function getSetKeyValue(value) {
...
@@ -1121,40 +1114,39 @@ function getSetKeyValue(value) {
let
valeuType
=
Object
.
prototype
.
toString
.
call
(
value
);
let
valeuType
=
Object
.
prototype
.
toString
.
call
(
value
);
let
newName
=
null
;
let
newName
=
null
;
let
extendJson
=
{
let
extendJson
=
{
"type"
:
"string"
type
:
'string'
,
};
};
if
(
valeuType
===
"[object String]"
)
{
if
(
valeuType
===
'[object String]'
)
{
newName
=
value
;
newName
=
value
;
}
}
if
(
valeuType
===
"[object Object]"
)
{
if
(
valeuType
===
'[object Object]'
)
{
newName
=
value
[
"new"
];
newName
=
value
[
'new'
];
delete
value
[
"new"
];
delete
value
[
'new'
];
extendJson
=
{
extendJson
=
{
...
extendJson
,
...
extendJson
,
...
value
...
value
,
};
};
}
}
return
{
return
{
newKey
:
newName
,
newKey
:
newName
,
...
extendJson
...
extendJson
,
}
};
}
}
function
getSetKeyJson
({
function
getSetKeyJson
({
obj
,
e
,
newKey
,
type
,
timeFormat
=
'YYYY-MM-DD HH:mm:ss'
,
defaultValue
})
{
obj
,
e
,
newKey
,
type
,
timeFormat
=
"YYYY-MM-DD HH:mm:ss"
,
defaultValue
})
{
obj
=
deepCopy
(
obj
);
obj
=
deepCopy
(
obj
);
let
value
=
obj
[
e
];
let
value
=
obj
[
e
];
let
newKeyObj
=
{};
let
newKeyObj
=
{};
// delete obj[e];
// delete obj[e];
switch
(
type
)
{
switch
(
type
)
{
case
"time"
:
case
'time'
:
newKeyObj
[
newKey
]
=
(
timeFormat
&&
value
?
moment
(
value
).
format
(
timeFormat
)
:
value
)
||
defaultValue
;
newKeyObj
[
newKey
]
=
(
timeFormat
&&
value
?
moment
(
value
).
format
(
timeFormat
)
:
value
)
||
defaultValue
;
break
;
break
;
case
"flow"
:
case
'flow'
:
newKeyObj
[
newKey
]
=
{
newKeyObj
[
newKey
]
=
{
"code"
:
value
||
defaultValue
,
code
:
value
||
defaultValue
,
"type"
:
"flow"
type
:
'flow'
,
};
};
break
;
break
;
default
:
default
:
...
@@ -1163,7 +1155,6 @@ function getSetKeyJson({
...
@@ -1163,7 +1155,6 @@ function getSetKeyJson({
return
newKeyObj
;
return
newKeyObj
;
}
}
// 下载附件FormdataWrapper
// 下载附件FormdataWrapper
function
isObject
(
value
)
{
function
isObject
(
value
)
{
return
value
===
Object
(
value
);
return
value
===
Object
(
value
);
...
@@ -1183,13 +1174,12 @@ function makeArrayKey(key) {
...
@@ -1183,13 +1174,12 @@ function makeArrayKey(key) {
export
function
FormdataWrapper
(
obj
,
fd
,
pre
)
{
export
function
FormdataWrapper
(
obj
,
fd
,
pre
)
{
fd
=
fd
||
new
FormData
();
fd
=
fd
||
new
FormData
();
Object
.
keys
(
obj
)
Object
.
keys
(
obj
).
forEach
(
function
(
prop
)
{
.
forEach
(
function
(
prop
)
{
var
key
=
pre
?
pre
+
'['
+
prop
+
']'
:
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
);
...
@@ -1204,7 +1194,6 @@ export function FormdataWrapper(obj, fd, pre) {
...
@@ -1204,7 +1194,6 @@ export function FormdataWrapper(obj, fd, pre) {
return
fd
;
return
fd
;
}
}
// TODO http://scjoyedu.eicp.net:57400/zentao/task-view-4023.html 等生产环境更新后测试.
// TODO http://scjoyedu.eicp.net:57400/zentao/task-view-4023.html 等生产环境更新后测试.
// http://xg.qnzy.net:51352/zyd/#/xg/student_affairs/MI/UrbanAndRuralMedicalInsurance/InsuredPersonnel
// http://xg.qnzy.net:51352/zyd/#/xg/student_affairs/MI/UrbanAndRuralMedicalInsurance/InsuredPersonnel
export
async
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
export
async
function
downloadFile
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
...
@@ -1218,10 +1207,15 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
...
@@ -1218,10 +1207,15 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
body
:
FormdataWrapper
(
params
),
body
:
FormdataWrapper
(
params
),
headers
,
headers
,
})
})
.
then
(
(
res
)
=>
{
.
then
(
async
(
res
)
=>
{
if
(
res
.
status
+
''
!==
'200'
)
{
if
(
res
.
status
+
''
!==
'200'
)
{
return
res
.
json
();
return
res
.
json
();
}
else
{
}
else
{
if
(
params
&&
params
.
showDownloadProgressFromFileName
)
{
// 2024年11月4日 解决禅道
showDownloadProgressFromFileName
(
res
,
{
ext
,
fileName
});
return
true
;
}
return
res
.
blob
();
return
res
.
blob
();
}
}
})
})
...
@@ -1236,7 +1230,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
...
@@ -1236,7 +1230,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
a
.
click
();
a
.
click
();
window
.
URL
.
revokeObjectURL
(
url
);
window
.
URL
.
revokeObjectURL
(
url
);
a
=
null
;
a
=
null
;
}
else
{
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
...
@@ -1247,7 +1240,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
...
@@ -1247,7 +1240,6 @@ export async function downloadFile(url, params, fileName = '导出文件', ext =
});
});
}
}
export
async
function
downloadFileAndShowModal
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
export
async
function
downloadFileAndShowModal
(
url
,
params
,
fileName
=
'导出文件'
,
ext
=
'xlsx'
)
{
const
{
transformApi
,
headersApi
}
=
await
getTransformApi
(
url
);
const
{
transformApi
,
headersApi
}
=
await
getTransformApi
(
url
);
let
headers
=
getSassApiHeader
();
let
headers
=
getSassApiHeader
();
...
@@ -1278,17 +1270,20 @@ export async function downloadFileAndShowModal(url, params, fileName = '导出
...
@@ -1278,17 +1270,20 @@ export async function downloadFileAndShowModal(url, params, fileName = '导出
Modal
.
info
({
Modal
.
info
({
title
:
filename
,
title
:
filename
,
width
:
1000
,
width
:
1000
,
content
:
<
div
>
content
:
(
<
embed
width
=
'100%'
<
div
>
height
=
'568px'
<
embed
name
=
'plugin'
width
=
"100%"
id
=
'pdfView'
height
=
"568px"
name
=
"plugin"
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
:
()
=>
{
window
.
URL
.
revokeObjectURL
(
url
);
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论