Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
2b0193de
提交
2b0193de
编写于
11月 17, 2022
作者:
Mosher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update:更新导入组件
上级
15327e67
变更
2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
557 行增加
和
395 行删除
+557
-395
app-data-upload.less
src/components/app-data-upload/app-data-upload.less
+130
-128
app-data-upload.vue
src/components/app-data-upload/app-data-upload.vue
+427
-267
未找到文件。
src/components/app-data-upload/app-data-upload.less
浏览文件 @
2b0193de
...
@@ -2,10 +2,11 @@
...
@@ -2,10 +2,11 @@
.app-data-upload-view{
.app-data-upload-view{
font-family: "Microsoft YaHei";
font-family: "Microsoft YaHei";
.main-content{
.main-content{
height: 174px
;
height: calc(100% - 68px)
;
background: #FAFAFB;
background: #FAFAFB;
border-radius: 4px;
border-radius: 4px;
border: 1px dashed #D7D7D7;
border: 1px dashed #D7D7D7;
margin-top: 10px;
// 上传文件区域
// 上传文件区域
.upload-container{
.upload-container{
cursor: pointer;
cursor: pointer;
...
@@ -96,6 +97,7 @@
...
@@ -96,6 +97,7 @@
.button-container{
.button-container{
text-align: right;
text-align: right;
margin: 15px;
margin: 15px;
height: 28px;
.el-button{
.el-button{
margin: 0 0 0 8px;
margin: 0 0 0 8px;
padding: 3px 15px;
padding: 3px 15px;
...
@@ -117,10 +119,10 @@
...
@@ -117,10 +119,10 @@
}
}
}
}
}
}
}
}
//模态样式
//模态样式
.view-default.app-data-upload-modal{
.view-default.app-data-upload-modal{
.app-data-upload-view{
.app-data-upload-view{
width: 100%;
width: 100%;
height: 100%;
height: 100%;
...
@@ -145,4 +147,4 @@
...
@@ -145,4 +147,4 @@
color: #999999;
color: #999999;
font-weight: 600;
font-weight: 600;
}
}
}
}
\ No newline at end of file
\ No newline at end of file
src/components/app-data-upload/app-data-upload.vue
浏览文件 @
2b0193de
<
template
>
<
template
>
<div
class=
"app-data-upload-view"
element-loading-background=
"rgba(57, 57, 57, 0.2)"
>
<div
class=
"app-data-upload-view"
v-loading
.
fullscreen=
"isUploading"
element-loading-background=
"rgba(57, 57, 57, 0.2)"
>
<input
<input
ref=
"inputUpLoad"
ref=
"inputUpLoad"
type=
"file"
type=
"file"
style=
"display: none"
style=
"display: none"
accept=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
accept=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
@
change=
"
fileChang
e"
@
change=
"
importFil
e"
/>
/>
<div
class=
"main-content"
>
<div
class=
"main-content"
>
<div
v-if=
"
!selectedFile
"
class=
"upload-container"
@
click=
"handleUpLoad"
>
<div
v-if=
"
importDataArray.length === 0 && !isUploading && uploadProgress !== 100
"
class=
"upload-container"
@
click=
"handleUpLoad"
>
<img
class=
"icon-import"
src=
"@/assets/img/icon-import.svg"
/>
<img
class=
"icon-import"
src=
"@/assets/img/icon-import.svg"
/>
<span
class=
"select-file-text"
>
{{
$t
(
'components.appDataUploadView.selectfile'
)
}}
</span>
<span
class=
"select-file-text"
>
{{
$t
(
"components.appDataUploadView.selectfile"
)
}}
</span>
</div>
<div
v-else
class=
"data-info-container"
>
<div
v-if=
"!isUploaded"
class=
"message-container"
>
<div
class=
"success-list"
v-if=
"!isUploading"
>
{{
$t
(
'components.appDataUploadView.selectfilesucess'
)
}}
</div>
<div
class=
"success-list"
v-if=
"isUploading"
>
导入过程中,请稍候
</div>
</div>
</div>
<div
v-else
class=
"message-container"
>
<div
class=
"data-info-container"
v-if=
"importDataArray.length > 0 || isUploading || uploadProgress == 100"
>
<div
class=
"result-list"
v-if=
"Object.keys(responseResult).length > 0"
>
<el-progress
<ul>
class=
"progress"
<li
class=
"title"
><span>
{{
$t
(
'components.appDataUploadView.importresult'
)
}}
</span></li>
v-show=
"isUploading"
<li>
:text-inside=
"true"
<span>
:stroke-width=
"14"
{{
$t
(
'components.appDataUploadView.totaldata'
)
}}
{{
responseResult
.
total
}}
{{
$t
(
'components.appDataUploadView.total'
)
}}
,
{{
$t
(
'app.commonwords.wrong'
)
}}
[
{{
responseResult
.
error
}}
],
{{
$t
(
'app.commonwords.success'
)
}}
[
{{
responseResult
.
success
}}
]
:percentage=
"uploadProgress"
</span>
></el-progress>
</li>
<span
class=
"font-class"
>
{{
promptInfo
}}
</span>
<template
v-if=
"responseResult.errorInfos && responseResult.errorInfos.length !== 0"
>
<li
class=
"title"
><span>
{{
$t
(
'components.appDataUploadView.errorinfo'
)
}}
</span></li>
<li
class=
"error-item"
v-for=
"(item, index) in responseResult.errorInfos"
:key=
"index"
>
<span
v-if=
"item.index"
>
{{
$t
(
'components.appDataUploadView.start'
)
}}
{{
item
.
index
}}
{{
$t
(
'components.appDataUploadView.row'
)
}}
:
</span><span
v-html=
"item.errorinfo"
></span>
</li>
</
template
>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<el-row
class=
"second-content"
>
<el-col>
<div
class=
"import-template-message"
>
{{ $t('components.appDataUploadView.datatemplatemessage') }}
</div>
<div
class=
"import-template"
>
<img
class=
"icon-link"
src=
"@/assets/img/icon-link.svg"
/>
<span
style=
"cursor: pointer"
@
click=
"downloadTemp"
>
{{ viewParams.appDeLogicName + $t('components.appDataUploadView.datatemplate') }}
</span
>
</div>
</el-col>
<div
class=
"import-template-download-info"
v-if=
"isUploaded && responseResult.errorfile"
@
click=
"downloadFeedbackMsg"
>
{{ $t('components.appDataUploadView.downloadinfo') }}
</div>
</el-row>
<el-row
class=
"button-container"
>
<el-row
class=
"button-container"
>
<el-button
type=
"primary"
@
click=
"handleCancel"
>
{{ $t(
'components.appDataUploadView.cancel'
) }}
</el-button>
<el-button
type=
"primary"
@
click=
"handleCancel"
>
{{
$t
(
"components.appDataUploadView.cancel"
)
}}
</el-button>
<el-button
<el-button
:disabled=
"
!selectedFile
"
:disabled=
"
importDataArray.length === 0
"
:loading=
"isUploading"
:loading=
"isUploading"
type=
"primary"
type=
"primary"
class=
"primary-button"
class=
"primary-button"
@
click=
"uploadServer"
@
click=
"uploadServer"
>
{{ $t(
'components.appDataUploadView.uploadserver'
) }}
</el-button
>
{{
$t
(
"components.appDataUploadView.uploadserver"
)
}}
</el-button
>
>
</el-row>
</el-row>
</div>
</div>
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
Environment
}
from
'@/environments/environment'
;
import
XLSX
from
"xlsx"
;
import
{
Util
}
from
'@/utils'
;
import
CodeListService
from
"@/codelist/codelist-service"
;
import
axios
from
'axios'
;
import
{
Vue
,
Component
,
Prop
,
Watch
}
from
"vue-property-decorator"
;
import
{
Vue
,
Component
,
Prop
,
Watch
}
from
'vue-property-decorator'
;
import
{
Environment
}
from
"@/environments/environment"
;
import
moment
from
"moment"
;
import
{
Util
}
from
"@/utils"
;
@
Component
({})
@
Component
({})
export
default
class
AppDataUploadView
extends
Vue
{
export
default
class
AppDataUploadView
extends
Vue
{
/**
* 传入视图上下文
*
* @type {string}
* @memberof AppDataUploadView
*/
@
Prop
()
protected
viewdata
!
:
string
;
@
Prop
()
public
viewparam
:
any
;
/**
* 传入视图参数
*
* @type {string}
* @memberof AppDataUploadView
*/
@
Prop
()
protected
viewparam
!
:
string
;
/**
/**
*
视图上下文
*
代码表服务对象
*
*
* @type {
*
}
* @type {
CodeListService
}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
@
Prop
()
public
viewdata
:
any
;
public
viewParams
:
any
=
{}
;
public
codeListService
:
CodeListService
=
new
CodeListService
({
$store
:
this
.
$store
})
;
public
context
:
any
=
{};
/**
* 实体服务对象
*
* @protected
* @type {EntityService}
* @memberof AppDataUploadView
*/
protected
entityService
:
any
;
/**
/**
*
选择文件数据
*
视图参数
*
*
* @type {*}
* @type {*}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
p
ublic
selectedFile
:
any
|
null
=
null
;
p
rotected
viewparams
:
any
=
{}
;
/**
/**
* 是否上传完成
* 导入数据模型
*
* @type {Array<*>}
* @memberof AppDataUploadView
*/
protected
importDataModel
:
Array
<
any
>
=
[];
/**
* 导入数据集合
*
* @type {Array<*>}
* @memberof AppDataUploadView
*/
public
importDataArray
:
Array
<
any
>
=
[];
/**
* 导入标识
*
* @type {string}
* @memberof AppDataUploadView
*/
protected
importId
:
string
=
""
;
/**
* 是否已有导入数据
*
*
* @type {boolean}
* @type {boolean}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
isUpload
ed
:
boolean
=
false
;
public
hasImport
ed
:
boolean
=
false
;
/**
/**
*
上传进度
*
导入数据识别项属性
*
*
* @type {number}
* @type {string}
* @memberof AppDataUploadView
*/
public
importUniqueItem
:
string
=
""
;
/**
* 提示信息
*
* @type {string}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
uploadedProgress
:
number
=
0
;
public
promptInfo
:
string
=
""
;
/**
/**
*
是否上传过程中
*
导入状态
*
*
* @type {boolean}
* @type {boolean}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
...
@@ -126,12 +150,60 @@ export default class AppDataUploadView extends Vue {
...
@@ -126,12 +150,60 @@ export default class AppDataUploadView extends Vue {
public
isUploading
:
boolean
=
false
;
public
isUploading
:
boolean
=
false
;
/**
/**
* 导入
结果集合
* 导入
成功数据
*
*
* @type {
Array<*>
}
* @type {
string
}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
responseResult
:
any
=
{};
public
importSuccessData
:
Array
<
any
>
=
[];
/**
* 导入失败数据
*
* @type {string}
* @memberof AppDataUploadView
*/
public
importErrorData
:
Array
<
any
>
=
[];
/**
* 读取完成的数据
*
* @type {*}
* @memberof AppDataUploadView
*/
public
workBookData
:
any
;
/**
* 所有的代码表
*
* @type {*}
* @memberof AppDataUploadView
*/
public
allCodeList
:
any
;
/**
* 属性Map(用作属性转化)
*
* @type {*}
* @memberof AppDataUploadView
*/
public
allFieldMap
:
Map
<
string
,
any
>
=
new
Map
();
/**
* 上传服务器数据切片数
*
* @type {number}
* @memberof AppDataUploadView
*/
public
sliceUploadCnt
:
number
=
Environment
.
sliceUploadCnt
;
/**
* 上传服务器进度条百分比
*
* @type {number}
* @memberof AppDataUploadView
*/
public
uploadProgress
:
number
=
0
;
/**
/**
* 视图参数变化
* 视图参数变化
...
@@ -140,20 +212,67 @@ export default class AppDataUploadView extends Vue {
...
@@ -140,20 +212,67 @@ export default class AppDataUploadView extends Vue {
* @param {*} oldVal
* @param {*} oldVal
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
@
Watch
(
'viewparam'
,
{
immediate
:
true
,
deep
:
true
})
@
Watch
(
"viewparam"
,
{
immediate
:
true
,
deep
:
true
})
onParamData
(
newVal
:
any
,
oldVal
:
any
)
{
onParamData
(
newVal
:
any
,
oldVal
:
any
)
{
if
(
newVal
)
{
if
(
newVal
)
{
this
.
viewParams
=
JSON
.
parse
(
newVal
);
Object
.
assign
(
this
.
viewparams
,
JSON
.
parse
(
this
.
viewparam
)
);
console
.
log
(
'视图残花'
,
this
.
viewParams
);
this
.
initBasic
(
);
}
}
}
}
@
Watch
(
'viewdata'
,
{
immediate
:
true
,
deep
:
true
})
/**
onViewDataChange
(
newVal
:
any
,
oldVal
:
any
)
{
* 初始化基础数据
if
(
newVal
)
{
*
this
.
context
=
JSON
.
parse
(
newVal
);
* @memberof AppDataUploadView
console
.
log
(
'上下文'
,
this
.
context
);
*/
public
async
initBasic
()
{
if
(
this
.
viewparams
.
importId
)
{
this
.
importId
=
this
.
viewparams
.
importId
;
}
if
(
this
.
viewparams
.
importData
)
{
this
.
importDataModel
=
Object
.
values
(
this
.
viewparams
.
importData
);
this
.
bubbleSort
(
this
.
importDataModel
,
this
.
importDataModel
.
length
);
}
this
.
importDataModel
.
forEach
((
item
:
any
)
=>
{
if
(
item
.
isuniqueitem
)
{
this
.
importUniqueItem
=
item
.
headername
;
}
this
.
allFieldMap
.
set
(
item
.
headername
,
item
);
});
if
(
this
.
viewparams
.
serviceName
)
{
this
.
entityService
=
await
window
.
entityServiceRegister
.
getService
(
this
.
viewparams
.
serviceName
.
toLowerCase
());
}
}
//获取代码表值
this
.
allCodeList
=
await
this
.
getChartAllCodeList
();
}
/**
* 冒泡排序
*
* @param {*} newVal
* @param {*} oldVal
* @memberof AppDataUploadView
*/
public
bubbleSort
(
array
:
Array
<
any
>
,
length
:
number
)
{
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
length
-
i
-
1
;
j
++
)
{
if
(
array
[
j
].
order
>
array
[
j
+
1
].
order
)
{
let
temp
:
any
;
temp
=
array
[
j
+
1
];
array
[
j
+
1
]
=
array
[
j
];
array
[
j
]
=
temp
;
}
}
}
}
/**
* 下载导入数据模板
*
* @memberof AppDataUploadView
*/
public
downloadTemp
()
{
this
.
importExcel
(
this
.
viewparams
.
appDeLogicName
+
this
.
$t
(
"components.appDataUploadView.datatemp"
),
[]);
}
}
/**
/**
...
@@ -162,247 +281,288 @@ export default class AppDataUploadView extends Vue {
...
@@ -162,247 +281,288 @@ export default class AppDataUploadView extends Vue {
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
handleUpLoad
()
{
public
handleUpLoad
()
{
this
.
importSuccessData
=
[];
(
this
.
$refs
.
inputUpLoad
as
any
).
click
();
(
this
.
$refs
.
inputUpLoad
as
any
).
click
();
}
}
/**
* 上传服务器
*
* @memberof AppDataUploadView
*/
public
uploadServer
()
{
if
(
this
.
importDataArray
.
length
==
0
||
!
this
.
entityService
)
{
return
;
}
let
tempDataArray
:
Array
<
any
>
=
[];
this
.
transformData
(
this
.
importDataArray
,
tempDataArray
);
this
.
hasImported
=
true
;
this
.
isUploading
=
true
;
this
.
uploadProgress
=
0
;
this
.
importDataArray
=
[];
this
.
sliceUploadService
(
tempDataArray
,
0
);
}
/**
* 数据切片上传
*
* @memberof AppDataUploadView
*/
public
sliceUploadService
(
dataArray
:
Array
<
any
>
,
cnt
:
number
)
{
if
(
cnt
>
dataArray
.
length
)
{
this
.
isUploading
=
false
;
this
.
uploadProgress
=
100
;
this
.
promptInfo
=
this
.
$t
(
"components.appDataUploadView.completed"
)
as
string
;
return
;
}
let
sliceArray
:
Array
<
any
>
=
[];
if
(
dataArray
)
{
sliceArray
=
dataArray
.
slice
(
cnt
,
cnt
+
this
.
sliceUploadCnt
);
}
try
{
this
.
entityService
.
ImportData
(
this
.
viewdata
,
{
name
:
this
.
importId
,
importData
:
sliceArray
})
.
then
((
res
:
any
)
=>
{
const
result
:
any
=
res
.
data
;
if
(
result
&&
result
.
rst
!==
0
)
{
this
.
promptInfo
=
this
.
$t
(
"components.appDataUploadView.importfailed"
)
as
string
;
this
.
isUploading
=
false
;
return
;
}
this
.
importSuccessData
=
result
.
data
;
this
.
promptInfo
=
this
.
$t
(
"components.appDataUploadView.completed"
)
as
string
;
this
.
uploadProgress
=
Number
(((
cnt
/
dataArray
.
length
)
*
100
).
toFixed
(
2
));
this
.
sliceUploadService
(
dataArray
,
cnt
+
this
.
sliceUploadCnt
);
})
.
catch
((
error
:
any
)
=>
{
this
.
isUploading
=
false
;
this
.
promptInfo
=
this
.
$t
(
"components.appDataUploadView.importfailed"
)
as
string
;
});
}
catch
(
error
:
any
)
{
this
.
isUploading
=
false
;
this
.
promptInfo
=
this
.
$t
(
"components.appDataUploadView.importfailed"
)
as
string
;
}
}
/**
/**
* 取消
* 取消
*
*
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
handleCancel
()
{
public
handleCancel
()
{
this
.
$emit
(
'close'
,
[]);
this
.
$emit
(
"close"
,
[]);
}
/**
* 导出excel
*
* @memberof AppDataUploadView
*/
public
async
importExcel
(
filename
:
string
,
_data
:
any
)
{
const
tHeader
:
Array
<
any
>
=
[];
this
.
importDataModel
.
forEach
((
item
:
any
)
=>
{
tHeader
.
push
(
item
.
headername
);
});
this
.
$export
.
exportExcel
().
then
((
excel
:
any
)
=>
{
excel
.
export_json_to_excel
({
header
:
tHeader
,
//表头 必填
data
:
[],
//具体数据 必填
filename
:
filename
,
//非必填
autoWidth
:
true
,
//非必填
bookType
:
"xlsx"
,
//非必填
});
});
}
/**
* 确认
*
* @memberof AppDataUploadView
*/
public
handleOK
()
{
this
.
$emit
(
"close"
,
this
.
importSuccessData
);
}
}
/**
/**
*
文件数据变化
*
导入Excel
*
*
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
fileChang
e
(
$event
:
any
)
{
public
importFil
e
(
$event
:
any
)
{
let
obj
=
$event
.
target
||
$event
.
srcElement
;
let
obj
=
$event
.
target
||
$event
.
srcElement
;
if
(
!
obj
.
files
)
{
if
(
!
obj
.
files
)
{
return
;
return
;
}
}
this
.
selectedFile
=
obj
.
files
&&
obj
.
files
.
length
>
0
?
obj
.
files
[
0
]
:
{};
let
f
=
obj
.
files
[
0
];
let
reader
=
new
FileReader
();
reader
.
onload
=
(
e
:
any
)
=>
{
let
data
=
e
.
target
.
result
;
this
.
workBookData
=
XLSX
.
read
(
data
,
{
type
:
"binary"
,
cellDates
:
true
});
let
xlsxData
=
XLSX
.
utils
.
sheet_to_json
(
this
.
workBookData
.
Sheets
[
this
.
workBookData
.
SheetNames
[
0
]]);
let
list1
=
this
.
getFirstRow
(
this
.
workBookData
);
xlsxData
=
this
.
addXlsxData
(
xlsxData
,
list1
);
this
.
importDataArray
=
Util
.
deepCopy
(
xlsxData
);
this
.
promptInfo
=
`
${
this
.
$t
(
'components.appDataUploadView.selectfilesucess'
)}
,
${
this
.
$t
(
'components.appDataUploadView.totaldata'
)}
${
this
.
importDataArray
.
length
}
${
this
.
$t
(
'components.appDataUploadView.total'
)}
`
;
(
this
.
$refs
.
inputUpLoad
as
any
).
value
=
""
;
};
reader
.
readAsBinaryString
(
f
);
}
}
/**
/**
*
设置UI状态
*
获取excel第一行的内容
*
*
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
setUIState
(
uploadedProgress
:
number
,
isUploading
:
boolean
,
isUploaded
:
boolean
,
result
:
any
=
{})
{
public
getFirstRow
(
wb
:
any
)
{
this
.
uploadedProgress
=
uploadedProgress
;
//// 读取的excel单元格内容
this
.
isUploading
=
isUploading
;
let
wbData
=
wb
.
Sheets
[
wb
.
SheetNames
[
0
]];
this
.
isUploaded
=
isUploaded
;
// 匹配excel第一行的内容
this
.
responseResult
=
result
;
let
re
=
/^
[
A-Z
]
1$/
;
let
temparr
=
[];
// excel第一行内容赋值给数组
for
(
let
key
in
wbData
)
{
if
(
wbData
.
hasOwnProperty
(
key
))
{
if
(
re
.
test
(
key
))
{
temparr
.
push
(
wbData
[
key
].
h
);
}
}
}
return
temparr
;
}
}
/**
/**
*
下载导入数据模板
*
增加对应字段空白内容
*
*
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
downloadTemp
()
{
public
addXlsxData
(
xlsxData
:
any
,
list1
:
any
)
{
let
requestUrl
:
string
=
''
;
// 空白字段替换值
if
(
this
.
viewdata
&&
this
.
context
.
srfparentkey
&&
this
.
context
.
srfparentdename
&&
this
.
context
.
srfparentdename
!==
this
.
viewdata
.
appEntityName
)
{
let
addData
=
null
;
requestUrl
+=
`/
${
Util
.
srfpluralize
(
this
.
viewdata
.
srfparentdename
)}
/
${
this
.
viewdata
.
srfparentkey
}
`
;
for
(
let
i
=
0
;
i
<
xlsxData
.
length
;
i
++
)
{
}
// 要被JSON的数组
requestUrl
+=
`/
${
Util
.
srfpluralize
(
this
.
viewParams
.
serviceName
)}
/importtemplate`
;
for
(
let
j
=
0
;
j
<
list1
.
length
;
j
++
)
{
if
(
this
.
viewParams
.
importId
)
{
// excel第一行内容
requestUrl
+=
`?srfimporttag=
${
this
.
viewParams
.
importId
}
`
;
if
(
!
xlsxData
[
i
][
list1
[
j
]])
{
}
xlsxData
[
i
][
list1
[
j
]]
=
addData
;
axios
({
url
:
requestUrl
,
method
:
'get'
,
responseType
:
'blob'
,
}).
then
((
response
:
any
)
=>
{
if
(
response
.
status
==
200
)
{
let
fileName
=
response
.
headers
[
'content-disposition'
]
.
split
(
';'
)
.
find
((
str
:
string
)
=>
str
.
indexOf
(
'filename='
)
!=
-
1
)
.
slice
(
9
);
fileName
=
decodeURIComponent
(
fileName
);
let
blob
=
new
Blob
([
response
.
data
],
{
type
:
'application/vnd.ms-excel'
});
let
elink
=
document
.
createElement
(
'a'
);
elink
.
download
=
fileName
;
elink
.
style
.
display
=
'none'
;
elink
.
href
=
URL
.
createObjectURL
(
blob
);
document
.
body
.
appendChild
(
elink
);
elink
.
click
();
URL
.
revokeObjectURL
(
elink
.
href
);
// 释放URL 对象
document
.
body
.
removeChild
(
elink
);
}
}
});
}
}
return
xlsxData
;
}
}
/**
/**
*
下载导入反馈信息
*
获取图表所需代码表
*
*
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
downloadFeedbackMsg
()
{
public
async
getChartAllCodeList
()
{
if
(
!
this
.
responseResult
||
!
this
.
responseResult
.
errorfile
||
!
this
.
responseResult
.
errorfile
.
fileid
){
let
codeListMap
:
Map
<
string
,
any
>
=
new
Map
();
this
.
$Notice
.
error
({
desc
:
this
.
$t
(
'components.appDataUploadView.downloaderror'
)
as
string
});
if
(
Object
.
values
(
this
.
importDataModel
).
length
>
0
)
{
return
;
await
Object
.
values
(
this
.
importDataModel
).
forEach
(
async
(
singleDataModel
:
any
)
=>
{
}
if
(
singleDataModel
.
codelist
)
{
let
downloadUrl
:
string
=
`
${
Environment
.
ExportFile
}
/
${
this
.
responseResult
.
errorfile
.
folder
}
/
${
this
.
responseResult
.
errorfile
.
fileid
}
`
;
let
tempCodeListMap
:
Map
<
any
,
any
>
=
new
Map
();
const
headers
=
{};
let
res
:
any
=
await
this
.
getCodeList
(
singleDataModel
.
codelist
);
axios
({
if
(
res
&&
res
.
length
>
0
)
{
method
:
'get'
,
res
.
forEach
((
codeListItem
:
any
)
=>
{
url
:
downloadUrl
,
tempCodeListMap
.
set
(
codeListItem
.
value
,
codeListItem
.
text
);
headers
:
headers
,
});
responseType
:
'blob'
}).
then
((
response
:
any
)
=>
{
if
(
!
response
||
response
.
status
!=
200
)
{
this
.
$Notice
.
error
({
desc
:
this
.
$t
(
'components.appDataUploadView.downloaderror'
)
as
string
});
return
;
}
}
// 请求成功,后台返回的是一个文件流
codeListMap
.
set
(
singleDataModel
.
codelist
.
tag
,
tempCodeListMap
);
if
(
response
.
data
)
{
// 获取文件名
const
filename
=
`导入错误
${
this
.
responseResult
.
errorfile
.
fileid
}
.xlsx`
;
let
filetype
=
this
.
calcFilemime
(
'xlsx'
);
// 用blob对象获取文件流
let
blob
=
new
Blob
([
response
.
data
],
{
type
:
filetype
});
// 通过文件流创建下载链接
var
href
=
URL
.
createObjectURL
(
blob
);
// 创建一个a元素并设置相关属性
let
a
=
document
.
createElement
(
'a'
);
a
.
href
=
href
;
a
.
download
=
filename
;
// 添加a元素到当前网页
document
.
body
.
appendChild
(
a
);
// 触发a元素的点击事件,实现下载
a
.
click
();
// 从当前网页移除a元素
document
.
body
.
removeChild
(
a
);
// 释放blob对象
URL
.
revokeObjectURL
(
href
);
}
else
{
this
.
$Notice
.
error
({
desc
:
this
.
$t
(
'components.appDataUploadView.downloaderror'
)
as
string
});
}
}
}).
catch
((
error
:
any
)
=>
{
console
.
error
(
error
);
});
});
}
}
return
codeListMap
;
/**
* 计算文件mime类型
*
* @param filetype 文件后缀
* @memberof AppDataUploadView
*/
public
calcFilemime
(
filetype
:
string
):
string
{
let
mime
=
"application/vnd.ms-excel"
;
switch
(
filetype
)
{
case
".xlsx"
:
mime
=
"application/vnd.ms-excel"
;
break
;
case
".wps"
:
mime
=
"application/kswps"
;
break
;
case
".doc"
:
mime
=
"application/msword"
;
break
;
case
".docx"
:
mime
=
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
;
break
;
case
".txt"
:
mime
=
"text/plain"
;
break
;
case
".zip"
:
mime
=
"application/zip"
;
break
;
case
".png"
:
mime
=
"image/png"
;
break
;
case
".gif"
:
mime
=
"image/gif"
;
break
;
case
".jpeg"
:
mime
=
"image/jpeg"
;
break
;
case
".jpg"
:
mime
=
"image/jpeg"
;
break
;
case
".rtf"
:
mime
=
"application/rtf"
;
break
;
case
".avi"
:
mime
=
"video/x-msvideo"
;
break
;
case
".gz"
:
mime
=
"application/x-gzip"
;
break
;
case
".tar"
:
mime
=
"application/x-tar"
;
break
;
}
return
mime
;
}
}
/**
/**
*
上传服务器
*
获取代码表
*
*
* @returns {Promise<any>}
* @memberof AppDataUploadView
* @memberof AppDataUploadView
*/
*/
public
uploadServer
()
{
public
getCodeList
(
codeListObject
:
any
):
Promise
<
any
>
{
if
(
!
this
.
selectedFile
)
{
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
return
;
if
(
codeListObject
.
tag
&&
Object
.
is
(
codeListObject
.
type
,
"STATIC"
))
{
const
codelist
=
this
.
$store
.
getters
.
getCodeList
(
codeListObject
.
tag
);
if
(
codelist
)
{
resolve
([...
JSON
.
parse
(
JSON
.
stringify
(
codelist
.
items
))]);
}
else
{
console
.
log
(
`----
${
codeListObject
.
tag
}
----
${
this
.
$t
(
"app.commonWords.codeNotExist"
)
as
string
}
`
);
}
}
try
{
}
else
if
(
codeListObject
.
tag
&&
Object
.
is
(
codeListObject
.
type
,
"DYNAMIC"
))
{
let
requestUrl
:
string
=
''
;
this
.
codeListService
this
.
setUIState
(
0
,
true
,
false
);
.
getItems
(
codeListObject
.
tag
)
if
(
this
.
viewdata
&&
this
.
viewdata
.
srfparentkey
&&
this
.
viewdata
.
srfparentdename
)
{
requestUrl
+=
`/
${
Util
.
srfpluralize
(
this
.
viewdata
.
srfparentdename
)}
/
${
this
.
viewdata
.
srfparentkey
}
`
;
}
requestUrl
+=
`/
${
Util
.
srfpluralize
(
this
.
viewParams
.
serviceName
)}
/importdata2`
;
if
(
this
.
viewParams
.
importId
)
{
requestUrl
+=
`?srfimporttag=
${
this
.
viewParams
.
importId
}
`
;
}
const
data
=
new
FormData
();
data
.
append
(
'file'
,
this
.
selectedFile
);
axios
.
post
(
requestUrl
,
data
,
{
headers
:
{
'Content-Type'
:
'multipart/form-data'
},
onUploadProgress
:
(
progressEvent
:
any
)
=>
{
this
.
uploadedProgress
=
Math
.
floor
((
progressEvent
.
loaded
/
progressEvent
.
total
)
*
100
);
},
})
.
then
((
res
:
any
)
=>
{
.
then
((
res
:
any
)
=>
{
const
result
:
any
=
{};
resolve
(
res
);
if
(
res
&&
res
.
status
&&
res
.
status
==
200
)
{
const
{
data
:
data
}
=
res
;
const
{
errorinfo
,
success
,
total
,
errorfile
}
=
data
;
result
.
total
=
total
?
Number
(
total
)
:
0
;
result
.
success
=
success
?
Number
(
success
)
:
0
;
result
.
errorfile
=
errorfile
;
if
(
errorinfo
&&
Object
.
keys
(
errorinfo
).
length
>
0
){
result
.
error
=
Object
.
keys
(
errorinfo
).
length
;
result
.
errorInfos
=
[];
Object
.
keys
(
errorinfo
).
forEach
((
item
:
any
)
=>
{
result
.
errorInfos
.
push
({
index
:
Number
(
item
)
+
1
,
errorinfo
:
errorinfo
[
item
].
errorInfo
});
})
})
.
catch
((
error
:
any
)
=>
{
console
.
log
(
`----
${
codeListObject
.
tag
}
----
${
this
.
$t
(
"app.commonWords.codeNotExist"
)
as
string
}
`
);
});
}
}
});
}
}
this
.
setUIState
(
0
,
false
,
true
,
result
);
}).
catch
((
error
:
any
)
=>
{
/**
const
errorResult
:
any
=
{};
* 转化数据
if
(
error
&&
error
.
status
&&
error
.
status
!==
200
)
{
*
errorResult
.
errorInfos
=
[];
* @memberof AppDataUploadView
errorResult
.
errorInfos
.
push
({
errorInfo
:
error
.
data
&&
error
.
data
.
message
?
error
.
data
.
message
:
''
});
*/
public
transformData
(
data
:
Array
<
any
>
,
result
:
Array
<
any
>
)
{
data
.
forEach
((
item
:
any
)
=>
{
let
curObject
:
any
=
{};
Object
.
keys
(
item
).
forEach
((
ele
:
any
)
=>
{
// todo XLSX读取时间为国际时间(东8区)+8H转为标准时间
if
(
item
[
ele
]
instanceof
Date
)
{
const
tempDate
:
Date
=
item
[
ele
];
item
[
ele
]
=
moment
(
tempDate
)
.
add
(
8
,
"h"
)
.
format
(
"YYYY-MM-DD HH:mm:ss"
);
}
}
this
.
setUIState
(
0
,
false
,
true
,
errorResult
);
if
(
this
.
allFieldMap
.
get
(
ele
).
codelist
)
{
let
codelistTag
:
string
=
this
.
allFieldMap
.
get
(
ele
).
codelist
.
tag
;
let
codelistIsNumber
:
boolean
=
this
.
allFieldMap
.
get
(
ele
).
codelist
.
isnumber
;
let
curCodeList
:
any
=
this
.
transCodeList
(
codelistTag
,
codelistIsNumber
,
true
);
Object
.
defineProperty
(
curObject
,
this
.
allFieldMap
.
get
(
ele
).
name
,
{
value
:
curCodeList
.
get
(
item
[
ele
]),
writable
:
true
,
enumerable
:
true
,
configurable
:
true
,
});
});
}
catch
(
error
:
any
)
{
}
else
{
this
.
setUIState
(
0
,
false
,
true
,
{
errorInfos
:[{
errorInfo
:
error
.
data
}]
});
Object
.
defineProperty
(
curObject
,
this
.
allFieldMap
.
get
(
ele
).
name
,
{
value
:
item
[
ele
],
writable
:
true
,
enumerable
:
true
,
configurable
:
true
,
});
}
});
result
.
push
(
curObject
);
});
}
/**
* 翻译代码表
*
* @memberof AppDataUploadView
*/
public
transCodeList
(
codeListTag
:
string
,
codelistIsNumber
:
boolean
,
isTransform
:
boolean
)
{
let
curCodeList
:
any
=
this
.
allCodeList
.
get
(
codeListTag
);
if
(
isTransform
)
{
let
tempCodelist
:
Map
<
string
,
string
>
=
new
Map
();
curCodeList
.
forEach
((
item
:
string
,
key
:
string
)
=>
{
let
value
:
any
=
codelistIsNumber
?
Number
(
key
)
:
key
;
tempCodelist
.
set
(
item
,
value
);
});
curCodeList
=
tempCodelist
;
}
}
return
curCodeList
;
}
}
}
}
</
script
>
</
script
>
<
style
lang=
'less'
>
<
style
lang=
"less"
>
@import
'./app-data-upload.less'
;
@import
"./app-data-upload.less"
;
</
style
>
</
style
>
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录