|
@@ -5,25 +5,24 @@ import { getMenuData } from './menu';
|
|
|
|
|
|
|
|
let routerDataCache;
|
|
let routerDataCache;
|
|
|
|
|
|
|
|
-const modelNotExisted = (app, model) => (
|
|
|
|
|
|
|
+const modelNotExisted = (app, model) =>
|
|
|
// eslint-disable-next-line
|
|
// eslint-disable-next-line
|
|
|
!app._models.some(({ namespace }) => {
|
|
!app._models.some(({ namespace }) => {
|
|
|
return namespace === model.substring(model.lastIndexOf('/') + 1);
|
|
return namespace === model.substring(model.lastIndexOf('/') + 1);
|
|
|
- })
|
|
|
|
|
-);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// wrapper of dynamic
|
|
// wrapper of dynamic
|
|
|
const dynamicWrapper = (app, models, component) => {
|
|
const dynamicWrapper = (app, models, component) => {
|
|
|
// () => require('module')
|
|
// () => require('module')
|
|
|
// transformed by babel-plugin-dynamic-import-node-sync
|
|
// transformed by babel-plugin-dynamic-import-node-sync
|
|
|
if (component.toString().indexOf('.then(') < 0) {
|
|
if (component.toString().indexOf('.then(') < 0) {
|
|
|
- models.forEach((model) => {
|
|
|
|
|
|
|
+ models.forEach(model => {
|
|
|
if (modelNotExisted(app, model)) {
|
|
if (modelNotExisted(app, model)) {
|
|
|
// eslint-disable-next-line
|
|
// eslint-disable-next-line
|
|
|
app.model(require(`../models/${model}`).default);
|
|
app.model(require(`../models/${model}`).default);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- return (props) => {
|
|
|
|
|
|
|
+ return props => {
|
|
|
if (!routerDataCache) {
|
|
if (!routerDataCache) {
|
|
|
routerDataCache = getRouterData(app);
|
|
routerDataCache = getRouterData(app);
|
|
|
}
|
|
}
|
|
@@ -36,20 +35,20 @@ const dynamicWrapper = (app, models, component) => {
|
|
|
// () => import('module')
|
|
// () => import('module')
|
|
|
return dynamic({
|
|
return dynamic({
|
|
|
app,
|
|
app,
|
|
|
- models: () => models.filter(
|
|
|
|
|
- model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`)
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ models: () =>
|
|
|
|
|
+ models.filter(model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`)),
|
|
|
// add routerData prop
|
|
// add routerData prop
|
|
|
component: () => {
|
|
component: () => {
|
|
|
if (!routerDataCache) {
|
|
if (!routerDataCache) {
|
|
|
routerDataCache = getRouterData(app);
|
|
routerDataCache = getRouterData(app);
|
|
|
}
|
|
}
|
|
|
- return component().then((raw) => {
|
|
|
|
|
|
|
+ return component().then(raw => {
|
|
|
const Component = raw.default || raw;
|
|
const Component = raw.default || raw;
|
|
|
- return props => createElement(Component, {
|
|
|
|
|
- ...props,
|
|
|
|
|
- routerData: routerDataCache,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return props =>
|
|
|
|
|
+ createElement(Component, {
|
|
|
|
|
+ ...props,
|
|
|
|
|
+ routerData: routerDataCache,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
@@ -57,7 +56,7 @@ const dynamicWrapper = (app, models, component) => {
|
|
|
|
|
|
|
|
function getFlatMenuData(menus) {
|
|
function getFlatMenuData(menus) {
|
|
|
let keys = {};
|
|
let keys = {};
|
|
|
- menus.forEach((item) => {
|
|
|
|
|
|
|
+ menus.forEach(item => {
|
|
|
if (item.children) {
|
|
if (item.children) {
|
|
|
keys[item.path] = { ...item };
|
|
keys[item.path] = { ...item };
|
|
|
keys = { ...keys, ...getFlatMenuData(item.children) };
|
|
keys = { ...keys, ...getFlatMenuData(item.children) };
|
|
@@ -68,7 +67,7 @@ function getFlatMenuData(menus) {
|
|
|
return keys;
|
|
return keys;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const getRouterData = (app) => {
|
|
|
|
|
|
|
+export const getRouterData = app => {
|
|
|
const routerConfig = {
|
|
const routerConfig = {
|
|
|
'/': {
|
|
'/': {
|
|
|
component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
|
|
component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
|
|
@@ -80,7 +79,9 @@ export const getRouterData = (app) => {
|
|
|
component: dynamicWrapper(app, ['monitor'], () => import('../routes/Dashboard/Monitor')),
|
|
component: dynamicWrapper(app, ['monitor'], () => import('../routes/Dashboard/Monitor')),
|
|
|
},
|
|
},
|
|
|
'/dashboard/workplace': {
|
|
'/dashboard/workplace': {
|
|
|
- component: dynamicWrapper(app, ['project', 'activities', 'chart'], () => import('../routes/Dashboard/Workplace')),
|
|
|
|
|
|
|
+ component: dynamicWrapper(app, ['project', 'activities', 'chart'], () =>
|
|
|
|
|
+ import('../routes/Dashboard/Workplace')
|
|
|
|
|
+ ),
|
|
|
// hideInBreadcrumb: true,
|
|
// hideInBreadcrumb: true,
|
|
|
// name: '工作台',
|
|
// name: '工作台',
|
|
|
// authority: 'admin',
|
|
// authority: 'admin',
|
|
@@ -131,7 +132,9 @@ export const getRouterData = (app) => {
|
|
|
component: dynamicWrapper(app, ['profile'], () => import('../routes/Profile/BasicProfile')),
|
|
component: dynamicWrapper(app, ['profile'], () => import('../routes/Profile/BasicProfile')),
|
|
|
},
|
|
},
|
|
|
'/profile/advanced': {
|
|
'/profile/advanced': {
|
|
|
- component: dynamicWrapper(app, ['profile'], () => import('../routes/Profile/AdvancedProfile')),
|
|
|
|
|
|
|
+ component: dynamicWrapper(app, ['profile'], () =>
|
|
|
|
|
+ import('../routes/Profile/AdvancedProfile')
|
|
|
|
|
+ ),
|
|
|
},
|
|
},
|
|
|
'/result/success': {
|
|
'/result/success': {
|
|
|
component: dynamicWrapper(app, [], () => import('../routes/Result/Success')),
|
|
component: dynamicWrapper(app, [], () => import('../routes/Result/Success')),
|
|
@@ -149,7 +152,9 @@ export const getRouterData = (app) => {
|
|
|
component: dynamicWrapper(app, [], () => import('../routes/Exception/500')),
|
|
component: dynamicWrapper(app, [], () => import('../routes/Exception/500')),
|
|
|
},
|
|
},
|
|
|
'/exception/trigger': {
|
|
'/exception/trigger': {
|
|
|
- component: dynamicWrapper(app, ['error'], () => import('../routes/Exception/triggerException')),
|
|
|
|
|
|
|
+ component: dynamicWrapper(app, ['error'], () =>
|
|
|
|
|
+ import('../routes/Exception/triggerException')
|
|
|
|
|
+ ),
|
|
|
},
|
|
},
|
|
|
'/user': {
|
|
'/user': {
|
|
|
component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
|
|
component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
|
|
@@ -174,7 +179,7 @@ export const getRouterData = (app) => {
|
|
|
// eg. {name,authority ...routerConfig }
|
|
// eg. {name,authority ...routerConfig }
|
|
|
const routerData = {};
|
|
const routerData = {};
|
|
|
// The route matches the menu
|
|
// The route matches the menu
|
|
|
- Object.keys(routerConfig).forEach((path) => {
|
|
|
|
|
|
|
+ Object.keys(routerConfig).forEach(path => {
|
|
|
// Regular match item name
|
|
// Regular match item name
|
|
|
// eg. router /user/:id === /user/chen
|
|
// eg. router /user/:id === /user/chen
|
|
|
const pathRegexp = pathToRegexp(path);
|
|
const pathRegexp = pathToRegexp(path);
|