Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
pro-blocks
Commits
ff08655f
Commit
ff08655f
authored
Aug 31, 2018
by
afc163
Committed by
偏右
Aug 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check every matched route for authority
parent
621299e7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
18 deletions
+76
-18
config/router.config.js
config/router.config.js
+65
-14
src/pages/Authorized.js
src/pages/Authorized.js
+11
-4
No files found.
config/router.config.js
View file @
ff08655f
...
@@ -28,8 +28,16 @@ module.exports = [
...
@@ -28,8 +28,16 @@ module.exports = [
name
:
'
analysis
'
,
name
:
'
analysis
'
,
component
:
'
./Dashboard/Analysis
'
,
component
:
'
./Dashboard/Analysis
'
,
},
},
{
path
:
'
/dashboard/monitor
'
,
name
:
'
monitor
'
,
component
:
'
./Dashboard/Monitor
'
},
{
{
path
:
'
/dashboard/workplace
'
,
name
:
'
workplace
'
,
component
:
'
./Dashboard/Workplace
'
},
path
:
'
/dashboard/monitor
'
,
name
:
'
monitor
'
,
component
:
'
./Dashboard/Monitor
'
,
},
{
path
:
'
/dashboard/workplace
'
,
name
:
'
workplace
'
,
component
:
'
./Dashboard/Workplace
'
,
},
],
],
},
},
// forms
// forms
...
@@ -84,16 +92,36 @@ module.exports = [
...
@@ -84,16 +92,36 @@ module.exports = [
icon
:
'
table
'
,
icon
:
'
table
'
,
name
:
'
list
'
,
name
:
'
list
'
,
routes
:
[
routes
:
[
{
path
:
'
/list/table-list
'
,
name
:
'
searchtable
'
,
component
:
'
./List/TableList
'
},
{
{
path
:
'
/list/basic-list
'
,
name
:
'
basiclist
'
,
component
:
'
./List/BasicList
'
},
path
:
'
/list/table-list
'
,
{
path
:
'
/list/card-list
'
,
name
:
'
cardlist
'
,
component
:
'
./List/CardList
'
},
name
:
'
searchtable
'
,
component
:
'
./List/TableList
'
,
},
{
path
:
'
/list/basic-list
'
,
name
:
'
basiclist
'
,
component
:
'
./List/BasicList
'
,
},
{
path
:
'
/list/card-list
'
,
name
:
'
cardlist
'
,
component
:
'
./List/CardList
'
,
},
{
{
path
:
'
/list/search
'
,
path
:
'
/list/search
'
,
name
:
'
searchlist
'
,
name
:
'
searchlist
'
,
component
:
'
./List/List
'
,
component
:
'
./List/List
'
,
routes
:
[
routes
:
[
{
path
:
'
/list/search/articles
'
,
name
:
'
articles
'
,
component
:
'
./List/Articles
'
},
{
{
path
:
'
/list/search/projects
'
,
name
:
'
projects
'
,
component
:
'
./List/Projects
'
},
path
:
'
/list/search/articles
'
,
name
:
'
articles
'
,
component
:
'
./List/Articles
'
,
},
{
path
:
'
/list/search/projects
'
,
name
:
'
projects
'
,
component
:
'
./List/Projects
'
,
},
{
{
path
:
'
/list/search/applications
'
,
path
:
'
/list/search/applications
'
,
name
:
'
applications
'
,
name
:
'
applications
'
,
...
@@ -109,8 +137,16 @@ module.exports = [
...
@@ -109,8 +137,16 @@ module.exports = [
icon
:
'
profile
'
,
icon
:
'
profile
'
,
routes
:
[
routes
:
[
// profile
// profile
{
path
:
'
/profile/basic
'
,
name
:
'
basic
'
,
component
:
'
./Profile/BasicProfile
'
},
{
{
path
:
'
/profile/advanced
'
,
name
:
'
advanced
'
,
component
:
'
./Profile/AdvancedProfile
'
},
path
:
'
/profile/basic
'
,
name
:
'
basic
'
,
component
:
'
./Profile/BasicProfile
'
,
},
{
path
:
'
/profile/advanced
'
,
name
:
'
advanced
'
,
component
:
'
./Profile/AdvancedProfile
'
,
},
],
],
},
},
{
{
...
@@ -119,7 +155,11 @@ module.exports = [
...
@@ -119,7 +155,11 @@ module.exports = [
path
:
'
/result
'
,
path
:
'
/result
'
,
routes
:
[
routes
:
[
// result
// result
{
path
:
'
/result/success
'
,
name
:
'
success
'
,
component
:
'
./Result/Success
'
},
{
path
:
'
/result/success
'
,
name
:
'
success
'
,
component
:
'
./Result/Success
'
,
},
{
path
:
'
/result/fail
'
,
name
:
'
fail
'
,
component
:
'
./Result/Error
'
},
{
path
:
'
/result/fail
'
,
name
:
'
fail
'
,
component
:
'
./Result/Error
'
},
],
],
},
},
...
@@ -129,9 +169,21 @@ module.exports = [
...
@@ -129,9 +169,21 @@ module.exports = [
path
:
'
/exception
'
,
path
:
'
/exception
'
,
routes
:
[
routes
:
[
// exception
// exception
{
path
:
'
/exception/403
'
,
name
:
'
not-permission
'
,
component
:
'
./Exception/403
'
},
{
{
path
:
'
/exception/404
'
,
name
:
'
not-find
'
,
component
:
'
./Exception/404
'
},
path
:
'
/exception/403
'
,
{
path
:
'
/exception/500
'
,
name
:
'
server-error
'
,
component
:
'
./Exception/500
'
},
name
:
'
not-permission
'
,
component
:
'
./Exception/403
'
,
},
{
path
:
'
/exception/404
'
,
name
:
'
not-find
'
,
component
:
'
./Exception/404
'
,
},
{
path
:
'
/exception/500
'
,
name
:
'
server-error
'
,
component
:
'
./Exception/500
'
,
},
{
{
path
:
'
/exception/trigger
'
,
path
:
'
/exception/trigger
'
,
name
:
'
trigger
'
,
name
:
'
trigger
'
,
...
@@ -172,7 +224,6 @@ module.exports = [
...
@@ -172,7 +224,6 @@ module.exports = [
path
:
'
/account/settings
'
,
path
:
'
/account/settings
'
,
name
:
'
settings
'
,
name
:
'
settings
'
,
component
:
'
./Account/Settings/Info
'
,
component
:
'
./Account/Settings/Info
'
,
// authority: ['admin'],
routes
:
[
routes
:
[
{
{
path
:
'
/account/settings
'
,
path
:
'
/account/settings
'
,
...
...
src/pages/Authorized.js
View file @
ff08655f
...
@@ -2,16 +2,23 @@ import React from 'react';
...
@@ -2,16 +2,23 @@ import React from 'react';
import
RenderAuthorized
from
'
@/components/Authorized
'
;
import
RenderAuthorized
from
'
@/components/Authorized
'
;
import
Exception
from
'
@/components/Exception
'
;
import
Exception
from
'
@/components/Exception
'
;
import
{
matchRoutes
}
from
'
react-router-config
'
;
import
{
matchRoutes
}
from
'
react-router-config
'
;
import
uniq
from
'
lodash/uniq
'
;
const
Authorized
=
RenderAuthorized
([
'
admin
'
,
'
user
'
]);
const
Authorized
=
RenderAuthorized
([
'
admin
'
,
'
user
'
]);
const
noMatch
=
<
Exception
type
=
"
403
"
style
=
{{
minHeight
:
500
,
height
:
'
80%
'
}}
/>
;
const
noMatch
=
<
Exception
type
=
"
403
"
style
=
{{
minHeight
:
500
,
height
:
'
80%
'
}}
/>
;
export
default
({
children
,
route
,
location
})
=>
{
export
default
({
children
,
route
,
location
})
=>
{
const
branch
=
const
routes
=
matchRoutes
(
route
.
routes
,
location
.
pathname
);
matchRoutes
(
route
.
routes
,
location
.
pathname
).
filter
(
item
=>
item
.
match
.
isExact
)[
0
]
||
{};
let
authorities
=
[];
const
{
authority
}
=
branch
.
route
||
{};
routes
.
forEach
(
item
=>
{
if
(
Array
.
isArray
(
item
.
authority
))
{
authorities
=
authorities
.
concat
(
item
.
authority
);
}
else
if
(
typeof
item
.
authority
===
'
string
'
)
{
authorities
.
push
(
item
.
authority
);
}
});
return
(
return
(
<
Authorized
authority
=
{
authority
}
noMatch
=
{
noMatch
}
>
<
Authorized
authority
=
{
uniq
(
authorities
)
}
noMatch
=
{
noMatch
}
>
{
children
}
{
children
}
<
/Authorized
>
<
/Authorized
>
);
);
...
...
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