明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
letian_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
letian_backend
Commits
481eb622
Commit
481eb622
authored
Nov 08, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
4bd44da3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
24 deletions
+27
-24
userController.js
controller/userController.js
+3
-2
userModule.js
module/userModule.js
+24
-22
No files found.
controller/userController.js
View file @
481eb622
...
@@ -52,6 +52,7 @@ async function login(req, res, next) {
...
@@ -52,6 +52,7 @@ async function login(req, res, next) {
if
(
!
user
)
{
if
(
!
user
)
{
return
res
.
sendError
(
errorMessage
.
loginError
);
return
res
.
sendError
(
errorMessage
.
loginError
);
}
}
//判断删除状态 ,暂时不加
const
check
=
utils
.
checkUserPassword
({
const
check
=
utils
.
checkUserPassword
({
reqPw
:
password
,
reqPw
:
password
,
salt
:
user
.
salt
,
salt
:
user
.
salt
,
...
@@ -64,10 +65,10 @@ async function login(req, res, next) {
...
@@ -64,10 +65,10 @@ async function login(req, res, next) {
let
token
=
crypto
.
randomUUID
();
let
token
=
crypto
.
randomUUID
();
user
.
token
=
token
.
split
(
'-'
).
join
(
""
);
user
.
token
=
token
.
split
(
'-'
).
join
(
""
);
let
userStr
=
JSON
.
stringify
(
user
);
let
userStr
=
JSON
.
stringify
(
user
);
console
.
log
(
userStr
,
"===="
)
await
ioRedis
.
set
(
`token:
${
user
.
token
}
`
,
userStr
,
'EX'
,
sysConfig
.
tokenEx
);
await
ioRedis
.
set
(
`token:
${
user
.
token
}
`
,
userStr
,
'EX'
,
sysConfig
.
tokenEx
);
let
ret
=
_
.
omit
(
user
,
[
'password'
,
'salt'
]);
let
ret
=
_
.
omit
(
user
,
[
'password'
,
'salt'
]);
let
menus
=
await
userModule
.
getRoleMenus
(
ret
.
roles
);
let
menus
=
await
userModule
.
getRoleMenus
(
ret
.
roles
,
user
.
mobile
);
ret
.
menus
=
menus
;
ret
.
menus
=
menus
;
res
.
sendData
(
ret
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
module/userModule.js
View file @
481eb622
...
@@ -11,10 +11,10 @@ async function findUserByMobile(mobile) {
...
@@ -11,10 +11,10 @@ async function findUserByMobile(mobile) {
if
(
!
mobile
)
{
if
(
!
mobile
)
{
return
null
;
return
null
;
}
}
const
user
=
await
DB
.
User
.
findOne
({
mobile
}).
populate
({
path
:
"roles"
,
select
:
"name key menus buttons"
,
match
:
{
del
:
{
$ne
:
1
}}
})
const
user
=
await
DB
.
User
.
findOne
({
mobile
}).
populate
({
path
:
"roles"
,
select
:
"name key menus buttons"
,
match
:
{
del
:
{
$ne
:
1
}
}
})
.
populate
({
path
:
"depart"
,
select
:
"name"
,
match
:
{
del
:
0
}
})
.
populate
({
path
:
"depart"
,
select
:
"name"
,
match
:
{
del
:
0
}
})
.
populate
({
path
:
"avatar"
})
.
populate
({
path
:
"avatar"
})
.
lean
().
exec
();
//{ path: "roles depart avatar" }
.
lean
().
exec
();
//{ path: "roles depart avatar" }
return
user
;
return
user
;
}
}
...
@@ -35,34 +35,37 @@ async function findOneAndUpdate(filter, updateObj) {
...
@@ -35,34 +35,37 @@ async function findOneAndUpdate(filter, updateObj) {
return
DB
.
User
.
findOneAndUpdate
(
filter
,
updateObj
);
return
DB
.
User
.
findOneAndUpdate
(
filter
,
updateObj
);
}
}
async
function
getRoleMenus
(
roles
)
{
async
function
getRoleMenus
(
roles
,
mobile
)
{
let
menuIds
=
[],
buttonIds
=
[];
let
menuIds
=
[],
buttonIds
=
[],
buts
=
[],
mes
=
[];
for
(
let
index
=
0
;
index
<
roles
.
length
;
index
++
)
{
if
(
mobile
==
"1111111111"
)
{
const
element
=
roles
[
index
];
buts
=
await
DB
.
Menu
.
find
({
del
:
0
}).
lean
().
exec
();
element
.
menus
=
element
.
menus
||
[];
mes
=
await
DB
.
Menu
.
find
({
del
:
0
,
type
:
1
,
enable
:
true
}).
populate
({
path
:
"parentIds"
}).
lean
().
exec
();
element
.
buttons
=
element
.
buttons
||
[];
}
else
{
menuIds
=
menuIds
.
concat
(
element
.
menus
);
for
(
let
index
=
0
;
index
<
roles
.
length
;
index
++
)
{
buttonIds
=
buttonIds
.
concat
(
element
.
buttons
);
const
element
=
roles
[
index
];
element
.
menus
=
element
.
menus
||
[];
element
.
buttons
=
element
.
buttons
||
[];
menuIds
=
menuIds
.
concat
(
element
.
menus
);
buttonIds
=
buttonIds
.
concat
(
element
.
buttons
);
}
buts
=
await
DB
.
Menu
.
find
({
del
:
0
,
_id
:
{
$in
:
buttonIds
}
}).
lean
().
exec
();
mes
=
await
DB
.
Menu
.
find
({
del
:
0
,
type
:
1
,
enable
:
true
,
_id
:
{
$in
:
menuIds
}
}).
populate
({
path
:
"parentIds"
}).
lean
().
exec
();
}
}
console
.
log
(
menuIds
)
let
buts
=
await
DB
.
Menu
.
find
({
del
:
0
,
_id
:
{
$in
:
buttonIds
}
}).
lean
().
exec
();
// 把按钮的最近一级的父节点,作为map的key,按钮在下面放到对应的菜单中
// 把按钮的最近一级的父节点,作为map的key,按钮在下面放到对应的菜单中
let
bMap
=
{};
let
bMap
=
{};
for
(
let
i
=
0
;
i
<
buts
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
buts
.
length
;
i
++
)
{
const
o
=
buts
[
i
];
const
o
=
buts
[
i
];
o
.
permission
=
true
;
o
.
permission
=
true
;
if
(
o
.
parentIds
&&
o
.
parentIds
.
length
>
0
)
{
if
(
o
.
parentIds
&&
o
.
parentIds
.
length
>
0
)
{
let
bpreId
=
o
.
parentIds
.
pop
();
let
bpreId
=
o
.
parentIds
.
pop
();
bMap
[
bpreId
]
=
bMap
[
bpreId
]
||
[];
bMap
[
bpreId
]
=
bMap
[
bpreId
]
||
[];
bMap
[
bpreId
].
push
(
o
);
bMap
[
bpreId
].
push
(
o
);
}
}
}
}
//获取用户有效的菜单 type : 1
//获取用户有效的菜单 type : 1
let
mes
=
await
DB
.
Menu
.
find
({
del
:
0
,
type
:
1
,
enable
:
true
,
_id
:
{
$in
:
menuIds
}
}).
populate
({
path
:
"parentIds"
}).
lean
().
exec
();
console
.
log
(
mes
)
let
nodes
=
[],
nodeMap
=
{};
let
nodes
=
[],
nodeMap
=
{};
for
(
let
index
=
0
;
index
<
mes
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
mes
.
length
;
index
++
)
{
const
element
=
mes
[
index
];
const
element
=
mes
[
index
];
...
@@ -84,7 +87,6 @@ async function getRoleMenus(roles) {
...
@@ -84,7 +87,6 @@ async function getRoleMenus(roles) {
nodeMap
[
element
.
_id
]
=
1
;
nodeMap
[
element
.
_id
]
=
1
;
}
}
}
}
console
.
log
(
nodes
,
"================"
);
let
tree
=
utils
.
buildTree
(
nodes
);
let
tree
=
utils
.
buildTree
(
nodes
);
return
tree
;
return
tree
;
}
}
...
...
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