Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
9
91isoft_web_vue3
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
张伯涛
91isoft_web_vue3
Commits
b62da2e6
Commit
b62da2e6
authored
Feb 02, 2024
by
张伯涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户管理导入功能完善
parent
29448d8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
27 deletions
+68
-27
index.ts
src/api/user/index.ts
+22
-8
index.vue
src/views/system/user/index.vue
+46
-19
No files found.
src/api/user/index.ts
View file @
b62da2e6
...
@@ -81,7 +81,21 @@ export function updateUserPassword(businessId: number, password: string) {
...
@@ -81,7 +81,21 @@ export function updateUserPassword(businessId: number, password: string) {
params
:
data
params
:
data
});
});
}
}
/**
* 用户状态修改
*
*/
export
function
changeUserStatus
(
businessId
:
number
,
flag
:
string
)
{
const
data
=
{
businessId
,
flag
}
return
request
({
url
:
'/system/user/changeStatus'
,
method
:
'put'
,
params
:
data
});
}
/**
/**
* 删除用户
* 删除用户
*
*
...
@@ -127,16 +141,16 @@ export function exportUser(queryParams: UserQuery) {
...
@@ -127,16 +141,16 @@ export function exportUser(queryParams: UserQuery) {
*
*
* @param file
* @param file
*/
*/
export
function
importUser
(
deptId
:
number
,
file
:
File
)
{
export
function
importUser
(
data
:
any
)
{
const
formData
=
new
FormData
();
formData
.
append
(
"file"
,
file
);
return
request
({
return
request
({
url
:
"/api/v1/users/_import"
,
url
:
'/system/user/importExcel'
,
method
:
"post"
,
method
:
"post"
,
params
:
{
deptId
:
deptId
},
data
:
formData
,
headers
:
{
headers
:
{
"Content-Type"
:
"multipart/form-data"
,
'Content-Type'
:
'multipart/form-data'
},
},
transformRequest
:
[(
data
)
=>
{
return
data
}],
data
,
});
});
}
}
src/views/system/user/index.vue
View file @
b62da2e6
...
@@ -6,11 +6,12 @@ defineOptions({
...
@@ -6,11 +6,12 @@ defineOptions({
name
:
"User"
,
name
:
"User"
,
inheritAttrs
:
false
,
inheritAttrs
:
false
,
});
});
import
{
getToken
}
from
'@/utils/auth'
import
{
import
{
getUserPage
,
getUserPage
,
getUserForm
,
getUserForm
,
deleteUsers
,
deleteUsers
,
changeUserStatus
,
addUser
,
addUser
,
updateUser
,
updateUser
,
updateUserPassword
,
updateUserPassword
,
...
@@ -82,6 +83,14 @@ const importData = reactive({
...
@@ -82,6 +83,14 @@ const importData = reactive({
deptId
:
undefined
,
deptId
:
undefined
,
file
:
undefined
,
file
:
undefined
,
fileList
:
[],
fileList
:
[],
// 是否禁用上传
isUploading
:
false
,
// 是否更新已经存在的用户数据
updateSupport
:
0
,
// 设置上传的请求头部
headers
:
{
Authorization
:
'Bearer '
+
getToken
()
},
// 上传的地址
url
:
import
.
meta
.
env
.
VITE_APP_BASE_API
+
'/system/user/importExcel'
});
});
const
passwordCheck
=
(
rule
:
any
,
value
:
any
,
callback
:
any
)
=>
{
const
passwordCheck
=
(
rule
:
any
,
value
:
any
,
callback
:
any
)
=>
{
const
pattern
=
/^
(?![
0-9
]
+$
)(?![
a-zA-Z
]
+$
)[
0-9A-Za-z
]{8,16}
$/
const
pattern
=
/^
(?![
0-9
]
+$
)(?![
a-zA-Z
]
+$
)[
0-9A-Za-z
]{8,16}
$/
...
@@ -168,6 +177,7 @@ async function loadDeptOptions() {
...
@@ -168,6 +177,7 @@ async function loadDeptOptions() {
* @param id 用户ID
* @param id 用户ID
*/
*/
async
function
openDialog
(
type
:
string
,
id
?:
number
)
{
async
function
openDialog
(
type
:
string
,
id
?:
number
)
{
dialog
.
type
=
type
;
if
(
dialog
.
type
===
"user-form"
)
{
if
(
dialog
.
type
===
"user-form"
)
{
// 用户表单弹窗
// 用户表单弹窗
await
loadDeptOptions
();
// 加载部门下拉数据源
await
loadDeptOptions
();
// 加载部门下拉数据源
...
@@ -176,12 +186,14 @@ async function openDialog(type: string, id?: number) {
...
@@ -176,12 +186,14 @@ async function openDialog(type: string, id?: number) {
dialog
.
title
=
"修改用户"
;
dialog
.
title
=
"修改用户"
;
await
getUserForm
(
id
).
then
(({
data
})
=>
{
await
getUserForm
(
id
).
then
(({
data
})
=>
{
Object
.
assign
(
formData
,
{
...
data
});
Object
.
assign
(
formData
,
{
...
data
});
const
roleIdsList
=
formData
.
roleIds
.
split
(
','
)
if
(
formData
.
roleIds
&&
formData
.
roleIds
.
length
>
0
)
{
formData
.
roleList
=
[]
const
roleIdsList
=
formData
.
roleIds
.
split
(
','
)
roleIdsList
.
forEach
(
item
=>
{
formData
.
roleList
=
[]
const
id
=
Number
(
item
)
roleIdsList
.
forEach
(
item
=>
{
formData
.
roleList
.
push
(
id
)
const
id
=
Number
(
item
)
})
formData
.
roleList
.
push
(
id
)
})
}
});
});
}
else
{
}
else
{
dialog
.
title
=
"新增用户"
;
dialog
.
title
=
"新增用户"
;
...
@@ -192,7 +204,6 @@ async function openDialog(type: string, id?: number) {
...
@@ -192,7 +204,6 @@ async function openDialog(type: string, id?: number) {
dialog
.
width
=
600
;
dialog
.
width
=
600
;
}
}
dialog
.
visible
=
true
;
dialog
.
visible
=
true
;
dialog
.
type
=
type
;
}
}
...
@@ -254,22 +265,36 @@ const handleSubmit = useThrottleFn(() => {
...
@@ -254,22 +265,36 @@ const handleSubmit = useThrottleFn(() => {
}
}
});
});
}
else
if
(
dialog
.
type
===
"user-import"
)
{
}
else
if
(
dialog
.
type
===
"user-import"
)
{
if
(
!
importData
?.
deptId
)
{
ElMessage
.
warning
(
"请选择部门"
);
return
false
;
}
if
(
!
importData
?.
file
)
{
if
(
!
importData
?.
file
)
{
ElMessage
.
warning
(
"上传Excel文件不能为空"
);
ElMessage
.
warning
(
"上传Excel文件不能为空"
);
return
false
;
return
false
;
}
}
importUser
(
importData
?.
deptId
,
importData
?.
file
).
then
((
response
)
=>
{
var
fileData
=
new
FormData
()
// 当前为空
ElMessage
.
success
(
response
.
data
);
fileData
.
append
(
'file'
,
importData
.
file
)
importUser
(
fileData
).
then
((
response
)
=>
{
ElMessage
.
success
(
response
.
message
);
closeDialog
();
closeDialog
();
resetQuery
();
resetQuery
();
});
});
}
}
},
3000
);
},
3000
);
/** 用户状态修改*/
function
handleStatusChange
(
row
:
any
)
{
const
text
=
row
.
flag
===
'1'
?
'启用'
:
'停用'
ElMessageBox
.
confirm
(
"是否确认操作?"
,
"警告"
,
{
confirmButtonText
:
"确定"
,
cancelButtonText
:
"取消"
,
type
:
"warning"
,
})
.
then
(()
=>
{
return
changeUserStatus
(
row
.
businessId
,
row
.
flag
)
}).
then
(()
=>
{
ElMessage
.
success
(
text
+
'成功'
);
})
.
catch
(
function
()
{
row
.
flag
=
row
.
flag
===
'0'
?
'1'
:
'0'
});
}
/** 删除用户 */
/** 删除用户 */
function
handleDelete
(
id
:
number
)
{
function
handleDelete
(
id
:
number
)
{
ElMessageBox
.
confirm
(
"确认删除用户?"
,
"警告"
,
{
ElMessageBox
.
confirm
(
"确认删除用户?"
,
"警告"
,
{
...
@@ -310,7 +335,6 @@ function downloadTemplate() {
...
@@ -310,7 +335,6 @@ function downloadTemplate() {
window
.
URL
.
revokeObjectURL
(
downloadUrl
);
window
.
URL
.
revokeObjectURL
(
downloadUrl
);
});
});
}
}
/** Excel文件 Change */
/** Excel文件 Change */
function
handleFileChange
(
file
:
any
)
{
function
handleFileChange
(
file
:
any
)
{
importData
.
file
=
file
.
raw
;
importData
.
file
=
file
.
raw
;
...
@@ -392,7 +416,7 @@ onMounted(() => {
...
@@ -392,7 +416,7 @@ onMounted(() => {
class=
"!w-[100px]"
class=
"!w-[100px]"
>
>
<el-option
label=
"启用"
value=
"1"
/>
<el-option
label=
"启用"
value=
"1"
/>
<el-option
label=
"
禁
用"
value=
"0"
/>
<el-option
label=
"
停
用"
value=
"0"
/>
</el-select>
</el-select>
</el-form-item>
</el-form-item>
...
@@ -648,12 +672,15 @@ onMounted(() => {
...
@@ -648,12 +672,15 @@ onMounted(() => {
>
>
<el-form-item
label=
"Excel文件"
>
<el-form-item
label=
"Excel文件"
>
<el-upload
<el-upload
accept=
".xlsx, .xls"
:headers=
"importData.headers"
:action=
"importData.url + '?updateSupport=' + importData.updateSupport"
:disabled=
"importData.isUploading"
:auto-upload=
"false"
ref=
"uploadRef"
ref=
"uploadRef"
action=
""
action=
""
drag
drag
accept=
".xlsx, .xls"
:limit=
"1"
:limit=
"1"
:auto-upload=
"false"
:file-list=
"importData.fileList"
:file-list=
"importData.fileList"
:on-change=
"handleFileChange"
:on-change=
"handleFileChange"
:on-exceed=
"handleFileExceed"
:on-exceed=
"handleFileExceed"
...
...
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