明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
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
zengfanpei
jt_backend
Commits
cbcfda95
Commit
cbcfda95
authored
Dec 01, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
bacfce52
Pipeline
#103971
passed with stage
in 3 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
10 deletions
+56
-10
departController.js
controller/departController.js
+41
-3
roleController.js
controller/roleController.js
+14
-7
userRouter.js
router/userRouter.js
+1
-0
No files found.
controller/departController.js
View file @
cbcfda95
...
@@ -30,8 +30,8 @@ async function updateDepart(req, res, next) {
...
@@ -30,8 +30,8 @@ async function updateDepart(req, res, next) {
if
(
!
body
.
id
)
{
if
(
!
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
}
if
(
body
.
parentId
)
{
if
(
body
.
parentId
)
{
let
parendNode
=
await
DB
.
Depart
.
findOne
({
where
:
{
id
:
body
.
parentId
},
raw
:
true
,
attributes
:
[
'parentIds'
]
});
let
parendNode
=
await
DB
.
Depart
.
findOne
({
where
:
{
id
:
body
.
parentId
},
raw
:
true
,
attributes
:
[
'parentIds'
]
});
if
(
!
parendNode
)
{
if
(
!
parendNode
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
}
...
@@ -98,7 +98,7 @@ async function deleteDepart(req, res, next) {
...
@@ -98,7 +98,7 @@ async function deleteDepart(req, res, next) {
}
}
let
parStr
=
curNode
.
parentIds
?
`
${
curNode
.
parentIds
}
,
${
curNode
.
id
}
`
:
curNode
.
id
;
//拼接父字符串查找所有的子
let
parStr
=
curNode
.
parentIds
?
`
${
curNode
.
parentIds
}
,
${
curNode
.
id
}
`
:
curNode
.
id
;
//拼接父字符串查找所有的子
const
ret
=
await
DB
.
Depart
.
update
(
const
ret
=
await
DB
.
Depart
.
update
(
{
del
:
1
},
{
del
:
1
},
{
{
where
:
{
where
:
{
[
Op
.
or
]:
[
[
Op
.
or
]:
[
...
@@ -125,6 +125,43 @@ async function getDepart(req, res, next) {
...
@@ -125,6 +125,43 @@ async function getDepart(req, res, next) {
}
}
}
}
async
function
getDepartUsers
(
req
,
res
,
next
)
{
try
{
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
let
offset
=
(
page
-
1
)
*
limit
;
if
(
!
req
.
body
.
departId
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
const
ret
=
await
DB
.
User
.
findAndCountAll
({
where
:
{
del
:
0
},
limit
,
offset
,
include
:
[
{
model
:
DB
.
Role
,
as
:
'roles'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Depart
,
as
:
'departs'
,
through
:
{
attributes
:
[]
},
},
{
model
:
DB
.
Position
,
as
:
'positions'
,
through
:
{
attributes
:
[]
},
}
]
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
module
.
exports
=
{
...
@@ -134,4 +171,5 @@ module.exports = {
...
@@ -134,4 +171,5 @@ module.exports = {
listDepart
,
listDepart
,
treeDepart
,
treeDepart
,
getDepart
,
getDepart
,
getDepartUsers
,
}
}
\ No newline at end of file
controller/roleController.js
View file @
cbcfda95
...
@@ -4,7 +4,13 @@ const userModule = require('../module/userModule');
...
@@ -4,7 +4,13 @@ const userModule = require('../module/userModule');
async
function
createRole
(
req
,
res
,
next
)
{
async
function
createRole
(
req
,
res
,
next
)
{
try
{
try
{
const
body
=
req
.
body
;
const
body
=
req
.
body
;
const
ret
=
await
DB
.
Role
.
create
(
body
);
let
ret
=
await
DB
.
Role
.
create
(
body
);
ret
=
ret
.
toJSON
();
if
(
body
.
menus
)
{
//如果这里前端给的是树形结构 需要把它拆成平行,//TODO:
body
.
menus
=
utils
.
disTree
(
body
.
menus
);
await
userModule
.
setRoleMenu
(
ret
.
id
,
body
.
menus
,
[]);
delete
body
.
menus
;
}
return
res
.
sendData
(
ret
);
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
}
catch
(
error
)
{
next
(
error
);
next
(
error
);
...
@@ -24,7 +30,7 @@ async function updateRole(req, res, next) {
...
@@ -24,7 +30,7 @@ async function updateRole(req, res, next) {
{
{
model
:
DB
.
Menu
,
model
:
DB
.
Menu
,
as
:
'menus'
,
as
:
'menus'
,
where
:
{
del
:
0
},
//
where: {del: 0},
attributes
:
[
"id"
],
attributes
:
[
"id"
],
through
:
{
attributes
:
[]
},
through
:
{
attributes
:
[]
},
}
}
...
@@ -33,9 +39,9 @@ async function updateRole(req, res, next) {
...
@@ -33,9 +39,9 @@ async function updateRole(req, res, next) {
if
(
!
(
role
&&
role
.
id
))
{
if
(
!
(
role
&&
role
.
id
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
}
if
(
body
.
menus
)
{
//如果这里前端给的是树形结构 需要把它拆成平行,//TODO:
if
(
body
.
menus
)
{
//
body.menus = utils.disTree(body.menus);
body
.
menus
=
utils
.
disTree
(
body
.
menus
);
await
userModule
.
setRoleMenu
(
role
.
id
,
body
.
menus
,
role
.
menus
);
await
userModule
.
setRoleMenu
(
role
.
id
,
body
.
menus
,
role
.
menus
||
[]
);
delete
body
.
menus
;
delete
body
.
menus
;
}
}
// sequelize 只有update 写时需要注意条件 不能为空
// sequelize 只有update 写时需要注意条件 不能为空
...
@@ -86,8 +92,8 @@ async function getRole(req, res, next) {
...
@@ -86,8 +92,8 @@ async function getRole(req, res, next) {
if
(
!
req
.
body
.
id
)
{
if
(
!
req
.
body
.
id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
}
cons
t
ret
=
await
DB
.
Role
.
findOne
({
le
t
ret
=
await
DB
.
Role
.
findOne
({
where
:
{
id
:
req
.
body
.
id
},
raw
:
true
,
where
:
{
id
:
req
.
body
.
id
},
include
:
[
include
:
[
{
{
model
:
DB
.
Menu
,
model
:
DB
.
Menu
,
...
@@ -98,6 +104,7 @@ async function getRole(req, res, next) {
...
@@ -98,6 +104,7 @@ async function getRole(req, res, next) {
}
}
]
]
});
});
ret
=
ret
.
toJSON
();
if
(
ret
&&
ret
.
menus
&&
ret
.
menus
.
length
)
{
if
(
ret
&&
ret
.
menus
&&
ret
.
menus
.
length
)
{
ret
.
menus
=
utils
.
buildTree
(
ret
.
menus
);
ret
.
menus
=
utils
.
buildTree
(
ret
.
menus
);
}
}
...
...
router/userRouter.js
View file @
cbcfda95
...
@@ -54,6 +54,7 @@ router.post('/depart/deleteDepart', departController.deleteDepart);
...
@@ -54,6 +54,7 @@ router.post('/depart/deleteDepart', departController.deleteDepart);
router
.
post
(
'/depart/listDepart'
,
departController
.
listDepart
);
router
.
post
(
'/depart/listDepart'
,
departController
.
listDepart
);
router
.
post
(
'/depart/treeDepart'
,
departController
.
treeDepart
);
router
.
post
(
'/depart/treeDepart'
,
departController
.
treeDepart
);
router
.
post
(
'/depart/getDepart'
,
departController
.
getDepart
);
router
.
post
(
'/depart/getDepart'
,
departController
.
getDepart
);
router
.
post
(
'/depart/getDepartUsers'
,
departController
.
getDepartUsers
);
/**
/**
* 职位
* 职位
...
...
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