Unverified Commit e6fe4979 authored by 陈帅's avatar 陈帅 Committed by GitHub

Revert "close page permission control (#3842)" (#3844)

This reverts commit e8c8f8b9.
parent e8c8f8b9
......@@ -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',
},
],
......
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();
}
);
}
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