Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cebe6f93
authored
Apr 01, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REVIEW 用户管理(导入用户)
parent
0a690416
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
93 deletions
+68
-93
src/api/system/user/index.ts
+1
-1
src/views/bpm/model/ModelImportForm.vue
+3
-3
src/views/system/user/UserImportForm.vue
+61
-86
src/views/system/user/index.vue
+3
-3
No files found.
src/api/system/user/index.ts
View file @
cebe6f93
...
...
@@ -48,7 +48,7 @@ export const exportUser = (params) => {
}
// 下载用户导入模板
export
const
importUserTemplate
Api
=
()
=>
{
export
const
importUserTemplate
=
()
=>
{
return
request
.
download
({
url
:
'/system/user/get-import-template'
})
}
...
...
src/views/bpm/model/ModelImportForm.vue
View file @
cebe6f93
...
...
@@ -8,7 +8,7 @@
:data=
"formData"
name=
"bpmnFile"
v-model:file-list=
"fileList"
:drag=
"true"
drag
:auto-upload=
"false"
accept=
".bpmn, .xml"
:limit=
"1"
...
...
@@ -77,7 +77,7 @@ const open = async () => {
}
defineExpose
({
open
})
// 提供 open 方法,用于打开弹窗
/**
重置
表单 */
/**
提交
表单 */
const
submitForm
=
async
()
=>
{
// 校验表单
if
(
!
formRef
)
return
...
...
@@ -98,7 +98,7 @@ const submitForm = async () => {
/** 文件上传成功 */
const
emit
=
defineEmits
([
'success'
])
// 定义 success 事件,用于操作成功后的回调
const
submitFormSuccess
=
async
(
response
:
any
)
:
Promise
<
void
>
=>
{
const
submitFormSuccess
=
async
(
response
:
any
)
=>
{
if
(
response
.
code
!==
0
)
{
message
.
error
(
response
.
msg
)
formLoading
.
value
=
false
...
...
src/views/system/user/
components/
UserImportForm.vue
→
src/views/system/user/UserImportForm.vue
View file @
cebe6f93
<
template
>
<Dialog
:title=
"upload.title"
:modelValue=
"showDialog"
width=
"400px"
append-to-body
@
close=
"closeDialog"
>
<Dialog
title=
"用户导入"
v-model=
"modelVisible"
width=
"400"
>
<el-upload
ref=
"uploadRef"
:action=
"importUrl + '?updateSupport=' + updateSupport"
:headers=
"uploadHeaders"
v-model:file-list=
"fileList"
drag
accept=
".xlsx, .xls"
:limit=
"1"
:headers=
"upload.headers"
:action=
"upload.url + '?updateSupport=' + upload.updateSupport"
:disabled=
"upload.isUploading"
:on-progress=
"handleFileUploadProgress"
:on-success=
"handleFileSuccess"
:on-success=
"submitFormSuccess"
:on-exceed=
"handleExceed"
:on-error=
"
excelUpload
Error"
:on-error=
"
submitForm
Error"
:auto-upload=
"false"
drag
:disabled=
"formLoading"
>
<Icon
icon=
"ep:upload"
/>
<div
class=
"el-upload__text"
>
将文件拖到此处,或
<em>
点击上传
</em></div>
<template
#
tip
>
<div
class=
"el-upload__tip text-center"
>
<div
class=
"el-upload__tip"
>
<el-checkbox
v-model=
"up
load.up
dateSupport"
/>
是否更新已经存在的用户数据
<el-checkbox
v-model=
"updateSupport"
/>
是否更新已经存在的用户数据
</div>
<span>
仅允许导入xls、xlsx格式文件。
</span>
<span>
仅允许导入 xls、xlsx 格式文件。
</span>
<el-link
type=
"primary"
:underline=
"false"
style=
"font-size: 12px; vertical-align: baseline"
@
click=
"importTemplate"
>
下载模板
</el-link
>
下载模板
</el-link>
</div>
</
template
>
</el-upload>
<
template
#
footer
>
<div
class=
"dialog-footer"
>
<el-button
type=
"primary"
@
click=
"submitFileForm"
>
确 定
</el-button>
<el-button
@
click=
"cancel"
>
取 消
</el-button>
</div>
<el-button
@
click=
"submitForm"
type=
"primary"
:disabled=
"formLoading"
>
确 定
</el-button>
<el-button
@
click=
"modelVisible = false"
>
取 消
</el-button>
</
template
>
</Dialog>
</template>
<
script
lang=
"ts"
setup
>
import
{
importUserTemplateApi
}
from
'@/api/system/user'
import
*
as
UserApi
from
'@/api/system/user'
import
{
getAccessToken
,
getTenantId
}
from
'@/utils/auth'
import
download
from
'@/utils/download'
const
emits
=
defineEmits
([
'success'
])
const
message
=
useMessage
()
// 消息弹窗
const
showDialog
=
ref
(
false
)
const
modelVisible
=
ref
(
false
)
// 弹窗的是否展示
const
formLoading
=
ref
(
false
)
// 表单的加载中
const
uploadRef
=
ref
()
const
importUrl
=
import
.
meta
.
env
.
VITE_BASE_URL
+
import
.
meta
.
env
.
VITE_API_URL
+
'/system/user/import'
const
uploadHeaders
=
ref
()
// 上传 Header 头
const
fileList
=
ref
([])
// 文件列表
const
updateSupport
=
ref
(
0
)
// 是否更新已经存在的用户数据
/** 打开弹窗 */
const
open
=
()
=>
{
modelVisible
.
value
=
true
resetForm
()
}
defineExpose
({
open
})
// 提供 open 方法,用于打开弹窗
// 用户导入参数
const
upload
=
reactive
({
// // 是否显示弹出层(用户导入)
// open: false,
// 弹出层标题(用户导入)
title
:
'用户导入'
,
// 是否禁用上传
isUploading
:
false
,
// 是否更新已经存在的用户数据
updateSupport
:
0
,
// 设置上传的请求头部
headers
:
{
/** 提交表单 */
const
submitForm
=
async
()
=>
{
if
(
fileList
.
value
.
length
==
0
)
{
message
.
error
(
'请上传文件'
)
return
}
// 提交请求
uploadHeaders
.
value
=
{
Authorization
:
'Bearer '
+
getAccessToken
(),
'tenant-id'
:
getTenantId
()
},
// 上传的地址
url
:
import
.
meta
.
env
.
VITE_BASE_URL
+
import
.
meta
.
env
.
VITE_API_URL
+
'/system/user/import'
})
// 文件上传中处理
const
handleFileUploadProgress
=
()
=>
{
upload
.
isUploading
=
true
}
formLoading
.
value
=
true
uploadRef
.
value
!
.
submit
()
}
// 文件上传成功处理
const
handleFileSuccess
=
(
response
:
any
)
=>
{
/** 文件上传成功 */
const
emits
=
defineEmits
([
'success'
])
const
submitFormSuccess
=
(
response
:
any
)
=>
{
if
(
response
.
code
!==
0
)
{
message
.
error
(
response
.
msg
)
formLoading
.
value
=
false
return
}
upload
.
isUploading
=
false
uploadRef
.
value
?.
clearFiles
()
// 拼接提示语
const
data
=
response
.
data
let
text
=
'上传成功数量:'
+
data
.
createUsernames
.
length
+
';'
...
...
@@ -106,49 +99,31 @@ const handleFileSuccess = (response: any) => {
text += '
<
' + username + '
:
' + data.failureUsernames[username] + '
>
'
}
message.alert(text)
// 发送操作成功的事件
emits('
success
')
closeDialog()
}
// 文件数超出提示
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('
上传失败,请您重新上传!
')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
// 重置上传状态和文件
formLoading.value = false
uploadRef.value?.clearFiles()
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('
最多只能上传一个文件!
')
}
// 上传错误提示
const excelUploadError = (e): void => {
console.log(e)
message.error('
导入数据失败,请您重新上传!
')
}
/** 下载模板操作 */
const importTemplate = async () => {
try {
const res = await importUserTemplateApi()
const res = await UserApi.importUserTemplate()
download.excel(res, '
用户导入模版
.
xls
'
)
}
catch
(
error
)
{
console
.
error
(
error
)
}
}
/* 弹框按钮操作 */
// 点击取消
const
cancel
=
()
=>
{
closeDialog
()
}
// 关闭弹窗
const
closeDialog
=
()
=>
{
showDialog
.
value
=
false
}
// 提交上传文件
const
submitFileForm
=
()
=>
{
uploadRef
.
value
?.
submit
()
}
const
openForm
=
()
=>
{
uploadRef
.
value
?.
clearFiles
()
showDialog
.
value
=
true
}
defineExpose
({
openForm
})
</
script
>
src/views/system/user/index.vue
View file @
cebe6f93
...
...
@@ -194,7 +194,7 @@ import download from '@/utils/download'
import
{
CommonStatusEnum
}
from
'@/utils/constants'
import
*
as
UserApi
from
'@/api/system/user'
import
UserForm
from
'./UserForm.vue'
import
UserImportForm
from
'./
components/
UserImportForm.vue'
import
UserImportForm
from
'./UserImportForm.vue'
import
UserAssignRoleForm
from
'./UserAssignRoleForm.vue'
import
DeptTree
from
'./DeptTree.vue'
const
message
=
useMessage
()
// 消息弹窗
...
...
@@ -250,10 +250,10 @@ const openForm = (type: string, id?: number) => {
formRef
.
value
.
open
(
type
,
id
)
}
/
/ 用户导入
/
** 用户导入 */
const
importFormRef
=
ref
()
const
handleImport
=
()
=>
{
importFormRef
.
value
?.
openForm
()
importFormRef
.
value
.
open
()
}
/** 修改用户状态 */
...
...
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