明树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
1d32af27
Commit
1d32af27
authored
Mar 13, 2026
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
e22e64ab
Pipeline
#108300
passed with stage
in 3 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
18 deletions
+24
-18
roleController.js
controller/roleController.js
+24
-18
No files found.
controller/roleController.js
View file @
1d32af27
const
errorMessage
=
require
(
"../utils/errorMessage"
);
const
userModule
=
require
(
'../module/userModule'
);
const
{
Op
}
=
require
(
'sequelize'
);
const
{
Op
}
=
require
(
'sequelize'
);
async
function
createRole
(
req
,
res
,
next
)
{
try
{
const
body
=
req
.
body
;
if
(
req
.
body
.
key
)
{
let
rt
=
await
DB
.
Role
.
findOne
({
where
:
{
key
:
req
.
body
.
key
,
del
:
0
}
});
if
(
rt
)
{
return
res
.
sendError
(
errorMessage
.
roleDuplicate
);
}
}
let
ret
=
await
DB
.
Role
.
create
(
body
);
ret
=
ret
.
toJSON
();
if
(
body
.
menus
)
{
//如果这里前端给的是树形结构 需要把它拆成平行,//TODO:
if
(
body
.
menus
)
{
//如果这里前端给的是树形结构 需要把它拆成平行,//TODO:
// body.menus = utils.disTree(body.menus);
await
userModule
.
setRoleMenu
(
ret
.
id
,
body
.
menus
,
[]);
delete
body
.
menus
;
...
...
@@ -25,7 +31,7 @@ async function updateRole(req, res, next) {
return
res
.
sendError
(
errorMessage
.
resourceNotFound
)
}
let
role
=
await
DB
.
Role
.
findOne
({
where
:
{
del
:
0
,
id
:
req
.
body
.
id
},
where
:
{
del
:
0
,
id
:
req
.
body
.
id
},
raw
:
true
,
include
:
[
{
...
...
@@ -37,19 +43,19 @@ async function updateRole(req, res, next) {
}
]
})
if
(
!
(
role
&&
role
.
id
))
{
if
(
!
(
role
&&
role
.
id
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
if
(
body
.
menus
)
{
if
(
body
.
menus
)
{
// body.menus = utils.disTree(body.menus);
console
.
log
(
body
.
menus
,
"==============="
)
await
userModule
.
setRoleMenu
(
role
.
id
,
body
.
menus
,
role
.
menus
||
[]);
delete
body
.
menus
;
}
// sequelize 只有update 写时需要注意条件 不能为空
if
(
role
.
key
!=
req
.
body
.
key
)
{
let
rt
=
await
DB
.
Role
.
findOne
({
where
:
{
key
:
req
.
body
.
key
,
del
:
0
}
});
if
(
rt
)
{
if
(
role
.
key
!=
req
.
body
.
key
)
{
let
rt
=
await
DB
.
Role
.
findOne
({
where
:
{
key
:
req
.
body
.
key
,
del
:
0
}
});
if
(
rt
)
{
return
res
.
sendError
(
errorMessage
.
roleDuplicate
);
}
}
...
...
@@ -71,7 +77,7 @@ async function deleteRole(req, res, next) {
// }
const
ret
=
await
DB
.
Role
.
update
({
del
:
1
},
{
where
:
{
id
:
req
.
body
.
id
}
});
//删除用户角色绑定
await
DB
.
UserRole
.
destroy
({
where
:
{
roleId
:
req
.
body
.
id
}
});
await
DB
.
UserRole
.
destroy
({
where
:
{
roleId
:
req
.
body
.
id
}
});
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
...
...
@@ -80,7 +86,7 @@ async function deleteRole(req, res, next) {
async
function
listRole
(
req
,
res
,
next
)
{
try
{
let
search
=
{
where
:
{
del
:
0
}
};
let
search
=
{
where
:
{
del
:
0
}
};
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
let
offset
=
(
page
-
1
)
*
limit
;
...
...
@@ -126,14 +132,14 @@ async function getRole(req, res, next) {
}
]
});
if
(
!
ret
)
{
if
(
!
ret
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
ret
=
ret
.
toJSON
();
console
.
log
(
ret
.
menus
,
"------------"
)
if
(
ret
&&
ret
.
menus
&&
ret
.
menus
.
length
)
{
if
(
ret
&&
ret
.
menus
&&
ret
.
menus
.
length
)
{
// ret.menus = utils.buildTree(ret.menus);
ret
.
menus
=
ret
.
menus
.
map
(
o
=>
{
return
o
&&
o
.
id
});
ret
.
menus
=
ret
.
menus
.
map
(
o
=>
{
return
o
&&
o
.
id
});
}
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
...
...
@@ -144,11 +150,11 @@ async function getRole(req, res, next) {
async
function
setRoleMenu
(
req
,
res
,
next
)
{
try
{
const
{
roleId
,
menuIds
}
=
req
.
body
;
if
(
!
roleId
)
{
const
{
roleId
,
menuIds
}
=
req
.
body
;
if
(
!
roleId
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
const
rolemenus
=
await
DB
.
RoleMenu
.
findAll
({
where
:
{
roleId
:
roleId
},
raw
:
true
});
const
rolemenus
=
await
DB
.
RoleMenu
.
findAll
({
where
:
{
roleId
:
roleId
},
raw
:
true
});
await
userModule
.
setRoleMenu
(
roleId
,
menuIds
,
rolemenus
);
return
res
.
sendData
();
}
catch
(
error
)
{
...
...
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