Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bkunyun
Project
Project
Details
Activity
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
sunyihao
bkunyun
Commits
2207e28b
Commit
2207e28b
authored
May 17, 2022
by
sunyihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化04
parent
fd875ced
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
7 deletions
+63
-7
usePass.ts
src/hooks/usePass.ts
+43
-0
index.ts
src/router/index.ts
+3
-3
permission.ts
src/store/modules/permission.ts
+1
-1
index.tsx
src/views/demo/index.tsx
+16
-3
No files found.
src/hooks/usePass.ts
0 → 100644
View file @
2207e28b
import
{
operation
,
route
}
from
"@/router"
;
import
{
useStores
}
from
"@/store"
;
import
{
useCallback
}
from
"react"
;
const
usePass
=
()
=>
{
const
{
permissionStore
}
=
useStores
();
const
isPass
=
useCallback
(
(
key
:
string
,
routes
?:
Array
<
route
|
operation
>
):
boolean
=>
{
if
(
routes
)
{
for
(
let
item
of
routes
)
{
if
(
item
.
id
===
key
)
{
return
true
;
}
else
if
(
item
.
type
===
"page"
&&
item
.
children
?.
length
&&
isPass
(
key
,
item
.
children
)
)
{
return
true
;
}
}
}
else
{
for
(
let
item
of
permissionStore
.
allRoutes
)
{
if
(
item
.
type
!==
"navigate"
&&
item
.
id
===
key
)
{
return
true
;
}
else
if
(
item
.
type
===
"page"
&&
item
.
children
?.
length
&&
isPass
(
key
,
item
.
children
)
)
{
return
true
;
}
}
}
return
false
;
},
[
permissionStore
.
allRoutes
]
);
return
isPass
;
};
export
default
usePass
;
src/router/index.ts
View file @
2207e28b
...
@@ -10,10 +10,10 @@ export type route = {
...
@@ -10,10 +10,10 @@ export type route = {
type
:
"page"
;
type
:
"page"
;
name
:
string
;
name
:
string
;
path
:
string
;
path
:
string
;
element
:
React
.
FC
<
{
childrenRoutes
?:
Array
<
route
|
navigate
|
operation
>
}
>
;
element
:
React
.
FC
<
{
childrenRoutes
?:
Array
<
route
|
operation
>
}
>
;
icon
?:
string
;
icon
?:
string
;
show
?:
boolean
;
show
?:
boolean
;
children
?:
Array
<
route
|
navigate
|
operation
>
;
children
?:
Array
<
route
|
operation
>
;
};
};
export
type
navigate
=
{
export
type
navigate
=
{
...
@@ -32,7 +32,7 @@ export const elements: {
...
@@ -32,7 +32,7 @@ export const elements: {
[
x
:
string
]:
({
[
x
:
string
]:
({
childrenRoutes
,
childrenRoutes
,
}:
{
}:
{
childrenRoutes
?:
Array
<
operation
>
;
childrenRoutes
?:
Array
<
route
|
operation
>
;
})
=>
JSX
.
Element
;
})
=>
JSX
.
Element
;
}
=
{
}
=
{
Demo
:
Demo
,
Demo
:
Demo
,
...
...
src/store/modules/permission.ts
View file @
2207e28b
...
@@ -6,7 +6,7 @@ class Permission {
...
@@ -6,7 +6,7 @@ class Permission {
makeAutoObservable
(
this
);
makeAutoObservable
(
this
);
}
}
allRoutes
:
Array
<
route
|
navigate
>
=
[];
allRoutes
:
Array
<
route
|
navigate
|
operation
>
=
[];
addRoutes
:
Array
<
Array
<
route
>>
=
[];
addRoutes
:
Array
<
Array
<
route
>>
=
[];
sidebarRouters
:
Array
<
route
>
=
[];
sidebarRouters
:
Array
<
route
>
=
[];
...
...
src/views/demo/index.tsx
View file @
2207e28b
import
{
useMessage
}
from
"@/components/MySnackbar"
;
import
{
useMessage
}
from
"@/components/MySnackbar"
;
import
{
operation
}
from
"@/router"
;
import
usePass
from
"@/hooks/usePass"
;
import
{
operation
,
route
}
from
"@/router"
;
import
{
Button
}
from
"@mui/material"
;
import
{
Button
}
from
"@mui/material"
;
import
{
Box
}
from
"@mui/system"
;
import
{
Box
}
from
"@mui/system"
;
import
React
from
"react"
;
import
{
useEffect
}
from
"react"
;
const
Demo
=
({
childrenRoutes
}:
{
childrenRoutes
?:
Array
<
operation
>
})
=>
{
const
Demo
=
({
childrenRoutes
,
}:
{
childrenRoutes
?:
Array
<
route
|
operation
>
;
})
=>
{
const
message
=
useMessage
();
const
message
=
useMessage
();
const
isPass
=
usePass
();
useEffect
(()
=>
{
console
.
log
(
isPass
(
"PROJECT_OVERIVEW_CREATE"
),
"11111111111"
);
console
.
log
(
isPass
(
"PROJECT_SUMMARY_MEMBER"
),
"2222222"
);
console
.
log
(
isPass
(
"test"
),
"33333"
);
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[]);
return
(
return
(
<
Box
>
<
Box
>
...
...
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