Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
342 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import BasicLayout from './BasicLayout'; | ||
import UserLayout from './UserLayout'; | ||
|
||
export default props => { | ||
const { location } = props; | ||
const { pathname } = location; | ||
if (/\/user/i.test(pathname)) { | ||
return <UserLayout {...props} />; | ||
} | ||
return <BasicLayout {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import pathToRegexp from 'path-to-regexp'; | ||
import Authorized from '@/utils/Authorized'; | ||
import Exception403 from './Exception/403'; | ||
|
||
export default ({ children, location }) => { | ||
/* eslint-disable no-underscore-dangle */ | ||
const { routerData } = window.g_app._store.getState().menu; | ||
const 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); | ||
}; | ||
|
||
return ( | ||
<Authorized | ||
authority={getRouteAuthority(location.pathname, routerData)} | ||
noMatch={<Exception403 />} | ||
> | ||
{children} | ||
</Authorized> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.