Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mes-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周远喜
mes-ui
Commits
185d14bf
Commit
185d14bf
authored
Aug 25, 2020
by
renjintao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api
parent
e4fed9fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
117 deletions
+150
-117
api.js
pages/import/api.js
+3
-0
process.vue
pages/import/process.vue
+147
-117
No files found.
pages/import/api.js
View file @
185d14bf
...
@@ -27,5 +27,8 @@ export default {
...
@@ -27,5 +27,8 @@ export default {
openExcel
(
params
)
{
//处理时打开以前上传的excel返回数据
openExcel
(
params
)
{
//处理时打开以前上传的excel返回数据
return
Api
.
post
(
`
${
systemUrl
}
/importcenter/open`
,
params
);
return
Api
.
post
(
`
${
systemUrl
}
/importcenter/open`
,
params
);
},
},
importUser
(
params
)
{
//用户管理导入
return
Api
.
post
(
`
${
systemUrl
}
/userimportservice/import`
,
params
);
},
}
}
pages/import/process.vue
View file @
185d14bf
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
<div
class=
"tip mr20"
>
共
{{
excelData
.
length
}}
条数据
</div>
<div
class=
"tip mr20"
>
共
{{
excelData
.
length
}}
条数据
</div>
</FormItem>
</FormItem>
<FormItem>
<FormItem>
<Button
type=
"primary"
>
导入
</Button>
<Button
type=
"primary"
@
click=
"openInfoModal"
>
导入
</Button>
</FormItem>
</FormItem>
</Form>
</Form>
</
template
>
</
template
>
...
@@ -48,6 +48,9 @@
...
@@ -48,6 +48,9 @@
</FormItem>
</FormItem>
</Form>
</Form>
</FooterToolbar>
</FooterToolbar>
<Modal
v-model=
"infoModal"
title=
"提示信息"
@
on-ok=
"importOk"
>
<p>
确定批量导入数据到
<span
class=
"red f16 fwBold ml10 mr10"
>
用户管理
</span>
模块下?
</p>
</Modal>
</div>
</div>
</template>
</template>
...
@@ -62,6 +65,8 @@ export default {
...
@@ -62,6 +65,8 @@ export default {
data
()
{
data
()
{
return
{
return
{
pageType
:
undefined
,
pageType
:
undefined
,
tabVal
:
0
,
infoModal
:
false
,
entity
:
{},
entity
:
{},
downUrl
:
fileUrlDown
,
downUrl
:
fileUrlDown
,
fileUrlPath
:
""
,
fileUrlPath
:
""
,
...
@@ -349,6 +354,7 @@ export default {
...
@@ -349,6 +354,7 @@ export default {
],
],
tdHeightExcel
:
""
,
tdHeightExcel
:
""
,
excelData
:
[],
excelData
:
[],
excelDataBack
:
[],
formatList
:
[
"xlsx"
],
formatList
:
[
"xlsx"
],
columnsImport
:
[],
columnsImport
:
[],
departArr
:
[],
//部门list
departArr
:
[],
//部门list
...
@@ -357,7 +363,7 @@ export default {
...
@@ -357,7 +363,7 @@ export default {
openDatas
:
[],
openDatas
:
[],
dataType
:
0
,
dataType
:
0
,
//粘贴excel内容start
//粘贴excel内容start
btnType
:
'default'
,
btnType
:
"default"
,
ghostStatus
:
false
,
ghostStatus
:
false
,
btnTxt
:
"打开粘贴Excel"
,
btnTxt
:
"打开粘贴Excel"
,
showTablePaste
:
false
,
showTablePaste
:
false
,
...
@@ -374,7 +380,7 @@ export default {
...
@@ -374,7 +380,7 @@ export default {
created
()
{
created
()
{
this
.
tdHeightExcel
=
window
.
innerHeight
-
180
;
this
.
tdHeightExcel
=
window
.
innerHeight
-
180
;
//导出对列表头进行预加载start
//导出对列表头进行预加载start
this
.
loadColum
(
this
.
columns0
);
//
this.loadColum(this.columns0);
this
.
$api
.
get
(
`
${
systemUrl
}
/Department/GetDepartments`
).
then
((
r
)
=>
{
this
.
$api
.
get
(
`
${
systemUrl
}
/Department/GetDepartments`
).
then
((
r
)
=>
{
this
.
departArr
=
r
.
result
.
items
;
this
.
departArr
=
r
.
result
.
items
;
});
});
...
@@ -403,6 +409,7 @@ export default {
...
@@ -403,6 +409,7 @@ export default {
this
.
dataType
=
0
;
this
.
dataType
=
0
;
this
.
sheetNames
=
[];
this
.
sheetNames
=
[];
this
.
excelData
=
[];
this
.
excelData
=
[];
this
.
excelDataBack
=
[];
Api
.
openExcel
({
Api
.
openExcel
({
id
:
v
,
id
:
v
,
}).
then
((
res
)
=>
{
}).
then
((
res
)
=>
{
...
@@ -421,7 +428,8 @@ export default {
...
@@ -421,7 +428,8 @@ export default {
//加载原文件列表
//加载原文件列表
dealOpenTable
(
val
)
{
dealOpenTable
(
val
)
{
this
.
excelData
=
this
.
openDatas
[
val
].
dataTable
;
this
.
excelData
=
this
.
openDatas
[
val
].
dataTable
;
var
tempCos
=
Object
.
keys
(
this
.
openDatas
[
val
].
dataTable
[
0
]);
this
.
excelDataBack
=
this
.
openDatas
[
val
].
dataTable
;
var
tempCos
=
Object
.
keys
(
this
.
openDatas
[
val
].
dataTable
[
0
]);
//获取列表标题
this
.
columnsImport
=
[];
this
.
columnsImport
=
[];
var
headersNow
=
[];
var
headersNow
=
[];
tempCos
.
forEach
((
el
)
=>
{
tempCos
.
forEach
((
el
)
=>
{
...
@@ -432,28 +440,6 @@ export default {
...
@@ -432,28 +440,6 @@ export default {
});
});
this
.
columnsImport
=
headersNow
;
this
.
columnsImport
=
headersNow
;
},
},
handleSubmit
()
{
this
.
$refs
.
form
.
validate
((
v
)
=>
{
if
(
v
)
{
this
.
disabled
=
true
;
Api
.
update
(
this
.
entity
)
.
then
((
r
)
=>
{
this
.
disabled
=
false
;
if
(
r
.
success
)
{
this
.
$Message
.
success
(
"保存成功"
);
this
.
$emit
(
"on-ok"
);
}
else
{
this
.
$Message
.
error
(
"保存失败"
);
}
})
.
catch
((
err
)
=>
{
this
.
disabled
=
false
;
this
.
$Message
.
error
(
"保存失败"
);
console
.
warn
(
err
);
});
}
});
},
//重新处理colum
//重新处理colum
loadColum
(
columns
)
{
loadColum
(
columns
)
{
let
tempCol
=
this
.
$u
.
clone
(
columns
);
let
tempCol
=
this
.
$u
.
clone
(
columns
);
...
@@ -463,6 +449,43 @@ export default {
...
@@ -463,6 +449,43 @@ export default {
}
}
});
});
this
.
columnsImport
=
tempCol
;
this
.
columnsImport
=
tempCol
;
//处理原始数据和表头进行对应
let
temCol
=
this
.
$u
.
clone
(
this
.
columnsImport
);
//原始数据表头
let
temColPage
=
this
.
$u
.
clone
(
columns
);
//需要显示的页面的表头
let
temData
=
this
.
$u
.
clone
(
this
.
excelDataBack
);
//原始数据
let
arrTitleUse
=
[];
////使用数据字典的字段
temColPage
.
forEach
((
elCode
)
=>
{
if
(
elCode
.
code
)
{
arrTitleUse
.
push
({
key
:
elCode
.
key
,
code
:
elCode
.
code
,
});
}
});
let
useData
=
[];
//重新组织list列表数据
temData
.
forEach
((
elData
,
index
)
=>
{
let
objTm
=
{};
temCol
.
forEach
((
elTitle
)
=>
{
objTm
[
elTitle
.
key
]
=
elData
[
elTitle
.
title
];
});
useData
.
push
(
objTm
);
});
//对列表里的数据字典项进行处理
useData
.
forEach
(
eles
=>
{
arrTitleUse
.
forEach
((
elem
)
=>
{
if
(
eles
[
elem
.
key
]
&&
eles
[
elem
.
key
]
!=
""
&&
eles
[
elem
.
key
]
!=
null
)
{
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
eles
[
elem
.
key
]
=
this
.
$u
.
dirCode
(
this
.
$store
.
getters
.
dictionaryByKey
(
elem
.
code
),
eles
[
elem
.
key
]
);
}
});
})
//alert(JSON.stringify(useData))
this
.
excelData
=
useData
;
// alert(JSON.stringify(useData))
},
},
//下载原excel文件
//下载原excel文件
downFile
()
{
downFile
()
{
...
@@ -486,7 +509,7 @@ export default {
...
@@ -486,7 +509,7 @@ export default {
this
.
pageType
=
undefined
;
this
.
pageType
=
undefined
;
this
.
btnTxt
=
"打开粘贴Excel"
;
this
.
btnTxt
=
"打开粘贴Excel"
;
this
.
showTablePaste
=
false
;
this
.
showTablePaste
=
false
;
this
.
btnType
=
'default'
;
this
.
btnType
=
"default"
;
this
.
ghostStatus
=
false
;
this
.
ghostStatus
=
false
;
},
},
async
beforeUpload
(
file
)
{
async
beforeUpload
(
file
)
{
...
@@ -505,6 +528,7 @@ export default {
...
@@ -505,6 +528,7 @@ export default {
this
.
dataType
=
1
;
this
.
dataType
=
1
;
this
.
columnsImport
=
[];
this
.
columnsImport
=
[];
this
.
excelData
=
[];
this
.
excelData
=
[];
this
.
excelDataBack
=
[];
const
sheet2JSONOpts
=
{
const
sheet2JSONOpts
=
{
defval
:
""
,
//给defval赋值为空的字符串
defval
:
""
,
//给defval赋值为空的字符串
};
};
...
@@ -534,98 +558,19 @@ export default {
...
@@ -534,98 +558,19 @@ export default {
result
.
push
(
obj
);
result
.
push
(
obj
);
}
}
this
.
excelData
=
result
;
this
.
excelData
=
result
;
},
this
.
excelDataBack
=
result
;
//对已选择了功能模块的列表信息进行处理,对表头也处理
dealSheet1
(
index
)
{
this
.
excelData
=
[];
var
tempColums
=
this
.
$u
.
clone
(
this
.
columnsImport
);
const
sheet2JSONOpts
=
{
defval
:
""
,
//给defval赋值为空的字符串
};
var
csv
=
XLSX
.
utils
.
sheet_to_csv
(
this
.
workBook
.
Sheets
[
this
.
workBook
.
SheetNames
[
index
]],
sheet2JSONOpts
);
var
lines
=
csv
.
split
(
"
\n
"
);
//第一行标题
var
headers
=
lines
[
0
].
split
(
","
);
var
arrTi
=
[];
//转换到colum后的list表头start
headers
.
forEach
((
elHead
)
=>
{
tempColums
.
forEach
((
elCol
)
=>
{
if
(
elHead
==
elCol
.
title
)
{
//elHead=elCol.key
arrTi
.
push
(
elCol
.
key
);
}
});
});
headers
=
arrTi
;
//转换到colum后的list表头end
var
result
=
[];
for
(
var
i
=
1
;
i
<
lines
.
length
-
1
;
i
++
)
{
var
obj
=
{};
var
currentline
=
lines
[
i
].
split
(
","
);
for
(
var
j
=
0
;
j
<
headers
.
length
;
j
++
)
{
obj
[
headers
[
j
]]
=
currentline
[
j
];
}
result
.
push
(
obj
);
}
//对读取的excel文件数据进行处理
var
arrTitleUse
=
[];
//使用数据字典的字段
tempColums
.
forEach
((
elCode
)
=>
{
if
(
elCode
.
code
)
{
arrTitleUse
.
push
({
key
:
elCode
.
key
,
code
:
elCode
.
code
,
});
}
});
result
.
forEach
((
ele
)
=>
{
//如果导入文件没有departmentid,但存在departmentTitle的话,通过title获取id
if
(
ele
.
departmentTitle
&&
ele
.
departmentTitle
!=
""
&&
(
!
ele
.
departmentId
||
ele
.
departmentId
==
""
)
)
{
this
.
departArr
.
forEach
((
e
)
=>
{
if
(
ele
.
departmentTitle
&&
ele
.
departmentTitle
==
e
.
name
)
{
ele
.
departmentId
=
e
.
id
;
}
});
}
else
if
(
//如果导入文件没有departmentTitle,但存在departmentid的话,通过id获取departmentTitle
ele
.
departmentId
&&
ele
.
departmentId
+
""
!=
""
&&
(
!
ele
.
departmentTitle
||
ele
.
departmentTitle
==
""
)
)
{
this
.
departArr
.
forEach
((
e
)
=>
{
if
(
ele
.
departmentId
&&
ele
.
departmentId
==
e
.
id
)
{
ele
.
departmentTitle
=
e
.
name
;
}
});
}
//对列表里的数据字典项进行处理
arrTitleUse
.
forEach
((
elem
)
=>
{
if
(
ele
[
elem
.
key
]
&&
ele
[
elem
.
key
]
!=
""
&&
ele
[
elem
.
key
]
!=
null
)
{
//如果数据字典项对应的DirName字段存在,通过name查询到对应的code,然后赋值
ele
[
elem
.
key
]
=
this
.
$u
.
dirCode
(
this
.
$store
.
getters
.
dictionaryByKey
(
elem
.
code
),
ele
[
elem
.
key
]
);
}
});
});
this
.
excelData
=
result
;
},
},
//切换sheet表重新加载
//切换sheet表重新加载
sheetClick
(
val
)
{
sheetClick
(
val
)
{
this
.
tabVal
=
val
if
(
this
.
dataType
==
0
)
{
if
(
this
.
dataType
==
0
)
{
this
.
dealOpenTable
(
val
);
this
.
dealOpenTable
(
val
);
}
else
{
}
else
{
this
.
dealSheet
(
val
);
this
.
dealSheet
(
val
);
}
}
if
(
this
.
pageType
!=
undefined
)
{
this
.
pageChange
(
this
.
pageType
)
}
},
},
//选择导入的模块 0:用户管理
//选择导入的模块 0:用户管理
pageChange
(
val
)
{
pageChange
(
val
)
{
...
@@ -636,8 +581,15 @@ export default {
...
@@ -636,8 +581,15 @@ export default {
case
1
:
case
1
:
this
.
loadColum
(
this
.
columns1
);
this
.
loadColum
(
this
.
columns1
);
break
;
break
;
case
undefined
:
if
(
this
.
dataType
==
0
)
{
this
.
load
(
this
.
eid
);
}
else
{
this
.
dealSheet
(
this
.
tabVal
);
}
break
;
default
:
default
:
this
.
loadColum
(
this
.
columns
0
);
this
.
loadColum
(
this
.
columns
1
);
}
}
},
},
handleClose
()
{
handleClose
()
{
...
@@ -645,31 +597,55 @@ export default {
...
@@ -645,31 +597,55 @@ export default {
},
},
cancelExcel
()
{
cancelExcel
()
{
this
.
excelData
=
[];
this
.
excelData
=
[];
this
.
excelDataBack
=
[];
this
.
$refs
.
uploadfile
.
clearFiles
();
this
.
$refs
.
uploadfile
.
clearFiles
();
this
.
$emit
(
"on-close"
);
this
.
$emit
(
"on-close"
);
},
},
//粘贴excel相关start
//粘贴excel相关start
openPaste
()
{
openPaste
()
{
if
(
this
.
btnTxt
==
"打开粘贴Excel"
)
{
if
(
this
.
btnTxt
==
"打开粘贴Excel"
)
{
this
.
btnType
=
'primary'
;
this
.
btnType
=
"primary"
;
this
.
ghostStatus
=
true
;
this
.
ghostStatus
=
true
;
this
.
showTablePaste
=
true
;
this
.
showTablePaste
=
true
;
this
.
btnTxt
=
"关闭粘贴Excel"
;
this
.
btnTxt
=
"关闭粘贴Excel"
;
}
else
{
}
else
{
this
.
btnType
=
'default'
;
this
.
btnType
=
"default"
;
this
.
ghostStatus
=
false
;
this
.
ghostStatus
=
false
;
this
.
showTablePaste
=
false
;
this
.
showTablePaste
=
false
;
this
.
btnTxt
=
"打开粘贴Excel"
;
this
.
btnTxt
=
"打开粘贴Excel"
;
}
}
},
},
//粘贴excel成功
handleSuccess
(
tableData
)
{
handleSuccess
(
tableData
)
{
this
.
excelData
=
[];
this
.
excelData
=
[];
this
.
excelDataBack
=
[];
this
.
columnsImport
=
[];
this
.
columnsImport
=
[];
this
.
sheetNames
=
[];
this
.
sheetNames
=
[];
this
.
pageType
=
undefined
;
//console.log(tableData);
//console.log(tableData);
this
.
columnsImport
=
tableData
.
columns
;
let
tabColum
=
tableData
.
columns
this
.
excelData
=
tableData
.
data
;
let
tabData
=
tableData
.
data
let
arrData
=
[]
tabData
.
forEach
(
ele
=>
{
let
objData
=
{}
tabColum
.
forEach
(
el
=>
{
objData
[
el
.
title
]
=
ele
[
el
.
key
]
})
arrData
.
push
(
objData
)
})
//处理title和key一致
tabColum
.
forEach
(
el
=>
{
el
.
key
=
el
.
title
})
//alert(JSON.stringify(arrData))
//alert(JSON.stringify(tabColum))
this
.
columnsImport
=
tabColum
;
this
.
excelData
=
arrData
;
this
.
excelDataBack
=
arrData
;
//alert(JSON.stringify(this.columnsImport))
//alert(JSON.stringify(this.excelDataBack))
},
},
//粘贴excel失败
handleError
(
tableData
,
errorIndex
)
{
handleError
(
tableData
,
errorIndex
)
{
//console.log(tableData, errorIndex);
//console.log(tableData, errorIndex);
this
.
$Message
.
error
(
"表格数据有误"
);
this
.
$Message
.
error
(
"表格数据有误"
);
...
@@ -680,11 +656,65 @@ export default {
...
@@ -680,11 +656,65 @@ export default {
this
.
pageType
=
undefined
;
this
.
pageType
=
undefined
;
this
.
btnTxt
=
"打开粘贴Excel"
;
this
.
btnTxt
=
"打开粘贴Excel"
;
this
.
showTablePaste
=
false
;
this
.
showTablePaste
=
false
;
this
.
btnType
=
'default'
;
this
.
btnType
=
"default"
;
this
.
ghostStatus
=
false
;
this
.
ghostStatus
=
false
;
this
.
load
(
this
.
eid
);
this
.
load
(
this
.
eid
);
},
},
openInfoModal
()
{
if
(
this
.
pageType
!=
undefined
)
{
this
.
infoModal
=
true
}
else
{
this
.
$Message
.
error
(
"请选择需要批量导入到的模块!"
)
}
},
//导入按钮操作
importOk
()
{
switch
(
this
.
pageType
)
{
case
0
:
this
.
importUser
();
break
;
case
1
:
this
.
loadColum
(
this
.
columns1
);
break
;
default
:
this
.
loadColum
(
this
.
columns1
);
}
},
//批量导入用户
importUser
()
{
let
tempData
=
this
.
$u
.
clone
(
this
.
excelData
);
let
tempList
=
[];
tempData
.
forEach
((
ele
)
=>
{
let
obj
=
{
userName
:
ele
.
userName
,
cardNo
:
ele
.
cardNo
,
gender
:
ele
.
gender
,
birthday
:
ele
.
birthday
,
degreeId
:
ele
.
degreeId
,
departmentId
:
ele
.
departmentId
,
status
:
ele
.
status
,
phone
:
ele
.
phone
,
email
:
ele
.
email
,
licensedToWork
:
ele
.
licensedToWork
,
positionId
:
ele
.
positionId
,
titleId
:
ele
.
titleId
,
departmentTitle
:
ele
.
departmentTitle
,
};
tempList
.
push
(
obj
);
});
let
parms
=
{
list
:
tempList
,
};
Api
.
importUser
(
parms
).
then
((
res
)
=>
{
if
(
res
.
success
)
{
this
.
$Message
.
success
(
"批量导入用户管理成功!"
);
this
.
cancelExcel
();
}
else
{
this
.
$Message
.
error
(
"批量导入用户管理失败!"
);
}
});
},
l
(
key
)
{
l
(
key
)
{
key
=
"user"
+
"."
+
key
;
key
=
"user"
+
"."
+
key
;
return
this
.
$t
(
key
);
return
this
.
$t
(
key
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment