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
A
ant-design-pro
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
ant-design-pro
Commits
d15923c9
Unverified
Commit
d15923c9
authored
Feb 27, 2019
by
陈小聪
Committed by
GitHub
Feb 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Umi Permission Routing (#3587)
Use Umi Permission Routing
parent
4ff141ad
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
42 deletions
+43
-42
config/router.config.js
config/router.config.js
+0
-1
src/layouts/BasicLayout.js
src/layouts/BasicLayout.js
+1
-31
src/models/menu.js
src/models/menu.js
+2
-1
src/pages/Authorized.js
src/pages/Authorized.js
+40
-9
No files found.
config/router.config.js
View file @
d15923c9
...
@@ -19,7 +19,6 @@ export default [
...
@@ -19,7 +19,6 @@ export default [
path
:
'
/
'
,
path
:
'
/
'
,
component
:
'
../layouts/BasicLayout
'
,
component
:
'
../layouts/BasicLayout
'
,
Routes
:
[
'
src/pages/Authorized
'
],
Routes
:
[
'
src/pages/Authorized
'
],
authority
:
[
'
admin
'
,
'
user
'
],
routes
:
[
routes
:
[
// dashboard
// dashboard
{
path
:
'
/
'
,
redirect
:
'
/dashboard/analysis
'
},
{
path
:
'
/
'
,
redirect
:
'
/dashboard/analysis
'
},
...
...
src/layouts/BasicLayout.js
View file @
d15923c9
...
@@ -4,14 +4,11 @@ import DocumentTitle from 'react-document-title';
...
@@ -4,14 +4,11 @@ import DocumentTitle from 'react-document-title';
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
ContainerQuery
}
from
'
react-container-query
'
;
import
{
ContainerQuery
}
from
'
react-container-query
'
;
import
classNames
from
'
classnames
'
;
import
classNames
from
'
classnames
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
Media
from
'
react-media
'
;
import
Media
from
'
react-media
'
;
import
Authorized
from
'
@/utils/Authorized
'
;
import
logo
from
'
../assets/logo.svg
'
;
import
logo
from
'
../assets/logo.svg
'
;
import
Footer
from
'
./Footer
'
;
import
Footer
from
'
./Footer
'
;
import
Header
from
'
./Header
'
;
import
Header
from
'
./Header
'
;
import
Context
from
'
./MenuContext
'
;
import
Context
from
'
./MenuContext
'
;
import
Exception403
from
'
../pages/Exception/403
'
;
import
PageLoading
from
'
@/components/PageLoading
'
;
import
PageLoading
from
'
@/components/PageLoading
'
;
import
SiderMenu
from
'
@/components/SiderMenu
'
;
import
SiderMenu
from
'
@/components/SiderMenu
'
;
import
getPageTitle
from
'
@/utils/getPageTitle
'
;
import
getPageTitle
from
'
@/utils/getPageTitle
'
;
...
@@ -73,29 +70,6 @@ class BasicLayout extends React.Component {
...
@@ -73,29 +70,6 @@ class BasicLayout extends React.Component {
};
};
}
}
getRouteAuthority
=
(
pathname
,
routeData
)
=>
{
const
routes
=
routeData
.
slice
();
// clone
const
getAuthority
=
(
routeDatas
,
path
)
=>
{
let
authorities
;
routeDatas
.
forEach
(
route
=>
{
// check partial route
if
(
pathToRegexp
(
`
${
route
.
path
}
(.*)`
).
test
(
path
))
{
if
(
route
.
authority
)
{
authorities
=
route
.
authority
;
}
// is exact route?
if
(
!
pathToRegexp
(
route
.
path
).
test
(
path
)
&&
route
.
routes
)
{
authorities
=
getAuthority
(
route
.
routes
,
path
);
}
}
});
return
authorities
;
};
return
getAuthority
(
routes
,
pathname
);
};
getLayoutStyle
=
()
=>
{
getLayoutStyle
=
()
=>
{
const
{
fixSiderbar
,
isMobile
,
collapsed
,
layout
}
=
this
.
props
;
const
{
fixSiderbar
,
isMobile
,
collapsed
,
layout
}
=
this
.
props
;
if
(
fixSiderbar
&&
layout
!==
'
topmenu
'
&&
!
isMobile
)
{
if
(
fixSiderbar
&&
layout
!==
'
topmenu
'
&&
!
isMobile
)
{
...
@@ -132,12 +106,10 @@ class BasicLayout extends React.Component {
...
@@ -132,12 +106,10 @@ class BasicLayout extends React.Component {
isMobile
,
isMobile
,
menuData
,
menuData
,
breadcrumbNameMap
,
breadcrumbNameMap
,
route
:
{
routes
},
fixedHeader
,
fixedHeader
,
}
=
this
.
props
;
}
=
this
.
props
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
isTop
=
PropsLayout
===
'
topmenu
'
;
const
routerConfig
=
this
.
getRouteAuthority
(
pathname
,
routes
);
const
contentStyle
=
!
fixedHeader
?
{
paddingTop
:
0
}
:
{};
const
contentStyle
=
!
fixedHeader
?
{
paddingTop
:
0
}
:
{};
const
layout
=
(
const
layout
=
(
<
Layout
>
<
Layout
>
...
@@ -165,9 +137,7 @@ class BasicLayout extends React.Component {
...
@@ -165,9 +137,7 @@ class BasicLayout extends React.Component {
{...
this
.
props
}
{...
this
.
props
}
/
>
/
>
<
Content
className
=
{
styles
.
content
}
style
=
{
contentStyle
}
>
<
Content
className
=
{
styles
.
content
}
style
=
{
contentStyle
}
>
<
Authorized
authority
=
{
routerConfig
}
noMatch
=
{
<
Exception403
/>
}
>
{
children
}
{
children
}
<
/Authorized
>
<
/Content
>
<
/Content
>
<
Footer
/>
<
Footer
/>
<
/Layout
>
<
/Layout
>
...
...
src/models/menu.js
View file @
d15923c9
...
@@ -97,6 +97,7 @@ export default {
...
@@ -97,6 +97,7 @@ export default {
state
:
{
state
:
{
menuData
:
[],
menuData
:
[],
routerData
:
[],
breadcrumbNameMap
:
{},
breadcrumbNameMap
:
{},
},
},
...
@@ -107,7 +108,7 @@ export default {
...
@@ -107,7 +108,7 @@ export default {
const
breadcrumbNameMap
=
memoizeOneGetBreadcrumbNameMap
(
menuData
);
const
breadcrumbNameMap
=
memoizeOneGetBreadcrumbNameMap
(
menuData
);
yield
put
({
yield
put
({
type
:
'
save
'
,
type
:
'
save
'
,
payload
:
{
menuData
,
breadcrumbNameMap
},
payload
:
{
menuData
,
breadcrumbNameMap
,
routerData
:
routes
},
});
});
},
},
},
},
...
...
src/pages/Authorized.js
View file @
d15923c9
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
RenderAuthorized
from
'
@/components/Authorized
'
;
import
{
getAuthority
}
from
'
@/utils/authority
'
;
import
Redirect
from
'
umi/redirect
'
;
import
Redirect
from
'
umi/redirect
'
;
import
pathToRegexp
from
'
path-to-regexp
'
;
import
{
connect
}
from
'
dva
'
;
import
Authorized
from
'
@/utils/Authorized
'
;
const
Authority
=
getAuthority
();
function
AuthComponent
({
children
,
location
,
routerData
,
status
})
{
const
Authorized
=
RenderAuthorized
(
Authority
)
;
const
isLogin
=
status
===
'
ok
'
;
export
default
({
children
})
=>
(
const
getRouteAuthority
=
(
pathname
,
routeData
)
=>
{
<
Authorized
authority
=
{
children
.
props
.
route
.
authority
}
noMatch
=
{
<
Redirect
to
=
"
/user/login
"
/>
}
>
const
routes
=
routeData
.
slice
();
// clone
{
children
}
<
/Authorized
>
const
getAuthority
=
(
routeDatas
,
path
)
=>
{
);
let
authorities
;
routeDatas
.
forEach
(
route
=>
{
// check partial route
if
(
pathToRegexp
(
`
${
route
.
path
}
(.*)`
).
test
(
path
))
{
if
(
route
.
authority
)
{
authorities
=
route
.
authority
;
}
// is exact route?
if
(
!
pathToRegexp
(
route
.
path
).
test
(
path
)
&&
route
.
routes
)
{
authorities
=
getAuthority
(
route
.
routes
,
path
);
}
}
});
return
authorities
;
};
return
getAuthority
(
routes
,
pathname
);
};
return
(
<
Authorized
authority
=
{
getRouteAuthority
(
location
.
pathname
,
routerData
)}
noMatch
=
{
isLogin
?
<
Redirect
to
=
"
/exception/403
"
/>
:
<
Redirect
to
=
"
/user/login
"
/>
}
>
{
children
}
<
/Authorized
>
);
}
export
default
connect
(({
menu
:
menuModel
,
login
:
loginModel
})
=>
({
routerData
:
menuModel
.
routerData
,
status
:
loginModel
.
status
,
}))(
AuthComponent
);
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