|
|
@ -6,28 +6,20 @@ import Authorized from '@/utils/Authorized'; |
|
|
|
|
|
|
|
|
function AuthComponent({ children, location, routerData, status }) { |
|
|
function AuthComponent({ children, location, routerData, status }) { |
|
|
const isLogin = status === 'ok'; |
|
|
const isLogin = status === 'ok'; |
|
|
|
|
|
const getRouteAuthority = (path, routeData) => { |
|
|
|
|
|
let authorities; |
|
|
|
|
|
routeData.forEach(route => { |
|
|
|
|
|
// match prefix
|
|
|
|
|
|
if (pathToRegexp(`${route.path}(.*)`).test(path)) { |
|
|
|
|
|
authorities = route.authority || authorities; |
|
|
|
|
|
|
|
|
const getRouteAuthority = (pathname, routeData) => { |
|
|
// get children authority recursively
|
|
|
const routes = routeData.slice(); // clone
|
|
|
if (route.routes) { |
|
|
|
|
|
authorities = getRouteAuthority(path, route.routes) || authorities; |
|
|
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 authorities; |
|
|
|
|
|
|
|
|
return getAuthority(routes, pathname); |
|
|
|
|
|
}; |
|
|
}; |
|
|
return ( |
|
|
return ( |
|
|
<Authorized |
|
|
<Authorized |
|
|
|