明树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
23df095d
Commit
23df095d
authored
Dec 08, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
effb255b
Pipeline
#104310
passed with stage
in 3 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
18 deletions
+44
-18
positionController.js
controller/positionController.js
+1
-0
roleController.js
controller/roleController.js
+6
-4
userController.js
controller/userController.js
+12
-7
menu.js
db/model/system/menu.js
+18
-1
userModule.js
module/userModule.js
+6
-5
index.js
utils/index.js
+1
-1
No files found.
controller/positionController.js
View file @
23df095d
...
...
@@ -42,6 +42,7 @@ async function listPosition(req, res, next) {
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
let
offset
=
(
page
-
1
)
*
limit
;
search
.
order
=
[[
'createdAt'
,
'DESC'
]];
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
...
...
controller/roleController.js
View file @
23df095d
...
...
@@ -8,7 +8,7 @@ async function createRole(req, res, next) {
let
ret
=
await
DB
.
Role
.
create
(
body
);
ret
=
ret
.
toJSON
();
if
(
body
.
menus
)
{
//如果这里前端给的是树形结构 需要把它拆成平行,//TODO:
body
.
menus
=
utils
.
disTree
(
body
.
menus
);
//
body.menus = utils.disTree(body.menus);
await
userModule
.
setRoleMenu
(
ret
.
id
,
body
.
menus
,
[]);
delete
body
.
menus
;
}
...
...
@@ -71,6 +71,7 @@ async function listRole(req, res, next) {
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
let
offset
=
(
page
-
1
)
*
limit
;
search
.
order
=
[[
'createdAt'
,
'DESC'
]];
if
(
req
.
body
.
name
)
{
search
.
where
=
{
[
Op
.
or
]:
[
...
...
@@ -99,15 +100,16 @@ async function getRole(req, res, next) {
{
model
:
DB
.
Menu
,
as
:
'menus'
,
where
:
{
del
:
0
},
//
attributes: ["id"],
//
where: {del: 0},
attributes
:
[
"id"
],
through
:
{
attributes
:
[]
},
}
]
});
ret
=
ret
.
toJSON
();
if
(
ret
&&
ret
.
menus
&&
ret
.
menus
.
length
)
{
ret
.
menus
=
utils
.
buildTree
(
ret
.
menus
);
// ret.menus = utils.buildTree(ret.menus);
ret
.
menus
=
ret
.
menus
.
map
(
o
=>
{
return
o
&&
o
.
id
});
}
return
res
.
sendData
(
ret
);
}
catch
(
error
)
{
...
...
controller/userController.js
View file @
23df095d
const
crypto
=
require
(
'crypto'
);
const
_
=
require
(
'lodash'
);
const
CryptoJS
=
require
(
'crypto-js'
);
const
{
Op
,
where
}
=
require
(
'sequelize'
);
const
{
Op
}
=
require
(
'sequelize'
);
const
userModule
=
require
(
'../module/userModule'
);
const
errorMessage
=
require
(
'../utils/errorMessage'
);
...
...
@@ -200,15 +200,16 @@ async function updateUser(req, res, next) {
through
:
{
attributes
:
[]
},
}
],
raw
:
true
,
//
raw: true,
});
console
.
log
(
user
)
user
=
user
.
toJSON
();
if
(
!
(
user
&&
user
.
id
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
if
(
body
.
departs
&&
body
.
departs
.
length
)
{
//跟现有情况对比 确定增删关系
const
departIds
=
body
.
departs
.
map
(
o
=>
{
return
o
&&
o
.
id
||
o
});
console
.
log
(
departIds
,
"=================="
)
await
userModule
.
setUserDepart
(
user
.
id
,
departIds
,
user
.
departs
||
[]);
console
.
log
(
'user.departs'
,
user
.
departs
);
delete
body
.
departs
;
...
...
@@ -239,11 +240,15 @@ async function listUser(req, res, next) {
let
page
=
req
.
body
.
page
||
1
;
let
limit
=
req
.
body
.
pageSize
||
10
;
let
offset
=
(
page
-
1
)
*
limit
;
search
.
order
=
[[
'createdAt'
,
'DESC'
]];
if
(
req
.
body
.
name
)
{
search
.
where
.
name
=
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}
}
if
(
req
.
body
.
mobile
)
{
search
.
where
.
mobile
=
{
[
Op
.
like
]:
`%
${
req
.
body
.
mobile
}
%`
}
search
.
where
=
{
[
Op
.
or
]:
[
{
name
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
name
}
%`
}},
{
mobile
:
{
[
Op
.
like
]:
`%
${
req
.
body
.
mobile
}
%`
}}
],
del
:
0
}
}
search
.
limit
=
limit
;
search
.
offset
=
offset
;
...
...
db/model/system/menu.js
View file @
23df095d
...
...
@@ -52,6 +52,22 @@ const Menu = sequelize.define('Menu', {
defaultValue
:
0
,
comment
:
"0 正常 1 删除"
},
createdAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(),
get
()
{
const
rawValue
=
this
.
getDataValue
(
'createdAt'
);
return
rawValue
?
moment
(
rawValue
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
''
;
}
},
updatedAt
:
{
// 同样处理 updatedAt
type
:
DataTypes
.
DATE
,
defaultValue
:
new
Date
(),
get
()
{
const
rawValue
=
this
.
getDataValue
(
'createdAt'
);
return
rawValue
?
moment
(
rawValue
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
:
''
;
}
}
},
{
tableName
:
'system_menu'
,
// 指定表名(如果与模型名不同)
...
...
@@ -60,7 +76,8 @@ const Menu = sequelize.define('Menu', {
// 同步模型到数据库(创建表)
Menu
.
sync
({
// force: false, // force: true 会删除已存在表并重新创建
force
:
false
,
// // force: true 会删除已存在表并重新创建
// alter: true
})
.
then
(()
=>
{
...
...
module/userModule.js
View file @
23df095d
const
{
Op
}
=
require
(
'sequelize'
);
/**
*
...
...
@@ -56,11 +57,11 @@ async function setUserDepart(userId, departIds, departs) {
}
}
if
(
needAddIds
.
length
)
{
let
objs
=
needAddIds
.
map
(
o
=>
{
return
{
userId
:
userId
,
role
Id
:
o
}
});
await
DB
.
User
Role
.
bulkCreate
(
objs
);
let
objs
=
needAddIds
.
map
(
o
=>
{
return
{
userId
:
userId
,
depart
Id
:
o
}
});
await
DB
.
User
Depart
.
bulkCreate
(
objs
);
}
if
(
needDelIds
.
length
)
{
await
DB
.
User
Role
.
destroy
({
where
:
{
userId
:
userId
,
role
Id
:
{
[
Op
.
in
]:
needDelIds
}
}
});
await
DB
.
User
Depart
.
destroy
({
where
:
{
userId
:
userId
,
depart
Id
:
{
[
Op
.
in
]:
needDelIds
}
}
});
}
}
...
...
@@ -88,11 +89,11 @@ async function setUserPosition(userId, positionIds, positions) {
}
}
if
(
needAddIds
.
length
)
{
let
objs
=
needAddIds
.
map
(
o
=>
{
return
{
userId
:
userId
,
role
Id
:
o
}
});
let
objs
=
needAddIds
.
map
(
o
=>
{
return
{
userId
:
userId
,
posi
Id
:
o
}
});
await
DB
.
UserPosition
.
bulkCreate
(
objs
);
}
if
(
needDelIds
.
length
)
{
await
DB
.
UserPosition
.
destroy
({
where
:
{
userId
:
userId
,
role
Id
:
{
[
Op
.
in
]:
needDelIds
}
}
});
await
DB
.
UserPosition
.
destroy
({
where
:
{
userId
:
userId
,
posi
Id
:
{
[
Op
.
in
]:
needDelIds
}
}
});
}
}
...
...
utils/index.js
View file @
23df095d
...
...
@@ -35,7 +35,7 @@ function buildTree(nodes, keyid = 'id') {
// 遍历所有节点,并将它们添加到对应父节点的children数组中
nodes
.
forEach
(
node
=>
{
const
parentId
=
String
(
node
.
parentId
);
if
(
parentId
!==
null
)
{
if
(
parentId
!==
null
&&
node
.
del
==
0
)
{
// 确保父节点在映射中存在
if
(
nodeMap
.
has
(
parentId
))
{
// 将当前节点添加到父节点的children数组中
...
...
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