Browse Source

Authorize the routes

pull/2098/head
afc163 8 years ago
committed by 偏右
parent
commit
631483e6c8
  1. 8
      config/router.config.js
  2. 1
      package.json
  3. 18
      src/pages/Authorized.js
  4. 2
      src/pages/Dashboard/Monitor.js

8
config/router.config.js

@ -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' },
],

1
package.json

@ -48,6 +48,7 @@
"react-document-title": "^2.0.3",
"react-dom": "^16.4.2",
"react-fittext": "^1.0.0",
"react-router-config": "^1.0.0-beta.4",
"react-router-dom": "^4.3.1",
"umi": "^2.0.0-beta.10"
},

18
src/pages/Authorized.js

@ -0,0 +1,18 @@
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>
);
};

2
src/pages/Dashboard/Monitor.js

@ -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 }) => ({

Loading…
Cancel
Save