From e6fe497964d8fc298a0e9e58b96deaac85df2fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 26 Mar 2019 16:05:31 +0800 Subject: [PATCH] Revert "close page permission control (#3842)" (#3844) This reverts commit e8c8f8b90da85737bf36e47e2d875dcce53b9396. --- config/router.config.js | 5 ++++- src/app.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/config/router.config.js b/config/router.config.js index 15630ca5..e954ced9 100644 --- a/config/router.config.js +++ b/config/router.config.js @@ -21,9 +21,10 @@ export default [ { path: '/', component: '../layouts/BasicLayout', + Routes: ['src/pages/Authorized'], routes: [ // dashboard - { path: '/', redirect: '/dashboard/analysis' }, + { path: '/', redirect: '/dashboard/analysis', authority: ['admin', 'user'] }, { path: '/dashboard', name: 'dashboard', @@ -87,6 +88,7 @@ export default [ { path: '/form/advanced-form', name: 'advancedform', + authority: ['admin'], component: './Forms/AdvancedForm', }, ], @@ -160,6 +162,7 @@ export default [ { path: '/profile/advanced', name: 'advanced', + authority: ['admin'], component: './Profile/AdvancedProfile', }, ], diff --git a/src/app.js b/src/app.js index 2e98b22b..0f35ff9a 100644 --- a/src/app.js +++ b/src/app.js @@ -1,3 +1,5 @@ +import fetch from 'dva/fetch'; + export const dva = { config: { onError(err) { @@ -6,6 +8,37 @@ export const dva = { }, }; +let authRoutes = {}; + +function ergodicRoutes(routes, authKey, authority) { + routes.forEach(element => { + if (element.path === authKey) { + if (!element.authority) element.authority = []; // eslint-disable-line + Object.assign(element.authority, authority || []); + } else if (element.routes) { + ergodicRoutes(element.routes, authKey, authority); + } + return element; + }); +} + +export function patchRoutes(routes) { + Object.keys(authRoutes).map(authKey => + ergodicRoutes(routes, authKey, authRoutes[authKey].authority) + ); + window.g_routes = routes; +} + export function render(oldRender) { - oldRender(); + fetch('/api/auth_routes') + .then(res => res.json()) + .then( + ret => { + authRoutes = ret; + oldRender(); + }, + () => { + oldRender(); + } + ); } -- GitLab