Commit 631483e6 authored by afc163's avatar afc163 Committed by 偏右

Authorize the routes

parent 92341fdd
......@@ -14,6 +14,7 @@ module.exports = [
{
path: '/',
component: '../layouts/BasicLayout',
Routes: ['src/pages/Authorized'],
routes: [
// dashboard
{ path: '/', redirect: '/dashboard/analysis' },
......@@ -22,7 +23,12 @@ module.exports = [
name: 'dashboard',
icon: 'dashboard',
routes: [
{ path: '/dashboard/analysis', name: 'analysis', component: './Dashboard/Analysis' },
{
path: '/dashboard/analysis',
authority: ['admin'],
name: 'analysis',
component: './Dashboard/Analysis',
},
{ path: '/dashboard/monitor', name: 'monitor', component: './Dashboard/Monitor' },
{ path: '/dashboard/workplace', name: 'workplace', component: './Dashboard/Workplace' },
],
......
import React from 'react';
import RenderAuthorized from '@/components/Authorized';
import Exception from '@/components/Exception';
import { matchRoutes } from 'react-router-config';
const Authorized = RenderAuthorized('user');
const noMatch = <Exception type="403" style={{ minHeight: 500, height: '80%' }} />;
export default ({ children, route, location }) => {
const branch =
matchRoutes(route.routes, location.pathname).filter(item => item.match.isExact)[0] || {};
const { authority } = branch.route || {};
return (
<Authorized authority={authority} noMatch={noMatch}>
{children}
</Authorized>
);
};
......@@ -18,7 +18,7 @@ const targetTime = new Date().getTime() + 3900000;
// use permission as a parameter
const havePermissionAsync = new Promise(resolve => {
// Call resolve on behalf of passed
setTimeout(() => resolve(), 1000);
setTimeout(() => resolve(), 100);
});
@Secured(havePermissionAsync)
@connect(({ monitor, loading }) => ({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment