diff --git a/scripts/fetch-block.js b/scripts/fetch-block.js index abbbbe792ed5cc542c4f81cbca02929f077d6a53..e55d80b4002806bd103f70fa79c63ee8c324629a 100644 --- a/scripts/fetch-block.js +++ b/scripts/fetch-block.js @@ -37,11 +37,14 @@ const findAllInstallRouter = router => { return routers; }; -const filterParentRouter = router => { +const filterParentRouter = (router, layout) => { return [...router] .map(item => { - if (item.routes) { - return { ...item, routes: filterParentRouter(item.routes) }; + if (item.routes && (!router.component || layout)) { + return { ...item, routes: filterParentRouter(item.routes, false) }; + } + if (item.redirect) { + return item; } return null; }) @@ -70,7 +73,7 @@ const execCmd = shell => { }; // replace router config -const parentRouter = filterParentRouter(router); +const parentRouter = filterParentRouter(router, true); const { routesPath, code } = getNewRouteCode(relativePath, parentRouter); // write ParentRouter fs.writeFileSync(routesPath, code); @@ -89,7 +92,7 @@ const installBlock = async () => { if (gitFiles.find(file => file.path === gitPath)) { console.log('install ' + chalk.green(item.name) + ' to: ' + chalk.yellow(item.path)); gitFiles = gitFiles.filter(file => file.path !== gitPath); - const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${ + const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --npm-client=cnpm --path=${ item.path }`; try { diff --git a/scripts/router.config.js b/scripts/router.config.js index 5de93dffd8223f51009dee05e0b25e3d562e9664..9cd389b7566de020bdef688487493bc422fccf5f 100644 --- a/scripts/router.config.js +++ b/scripts/router.config.js @@ -4,7 +4,6 @@ module.exports = [ path: '/user', component: '../layouts/UserLayout', routes: [ - { path: '/user', redirect: '/user/login' }, { path: '/user/login', name: 'login', component: './User/Login' }, { path: '/user/register', name: 'register', component: './User/Register' }, { @@ -12,6 +11,7 @@ module.exports = [ name: 'register.result', component: './User/RegisterResult', }, + { path: '/user', redirect: '/user/login' }, { component: '404', }, @@ -25,7 +25,6 @@ module.exports = [ authority: ['admin', 'user'], routes: [ // dashboard - { path: '/', redirect: '/dashboard/analysis', authority: ['admin', 'user'] }, { path: '/dashboard', name: 'dashboard', @@ -63,28 +62,6 @@ module.exports = [ path: '/form/step-form', name: 'stepform', component: './Form/StepForm', - hideChildrenInMenu: true, - // routes: [ - // { - // path: '/form/step-form', - // redirect: '/form/step-form/info', - // }, - // { - // path: '/form/step-form/info', - // name: 'info', - // component: './Form/StepForm/Step1', - // }, - // { - // path: '/form/step-form/confirm', - // name: 'confirm', - // component: './Form/StepForm/Step2', - // }, - // { - // path: '/form/step-form/result', - // name: 'result', - // component: './Form/StepForm/Step3', - // }, - // ], }, { path: '/form/advanced-form', @@ -120,10 +97,6 @@ module.exports = [ name: 'search-list', component: './list/search', routes: [ - { - path: '/list/search', - redirect: '/list/search/articles', - }, { path: '/list/search/articles', name: 'articles', @@ -139,6 +112,10 @@ module.exports = [ name: 'applications', component: './list/Applications', }, + { + path: '/list/search', + redirect: '/list/search/articles', + }, ], }, ], @@ -213,51 +190,11 @@ module.exports = [ path: '/account/center', name: 'center', component: './Account/Center/Center', - // routes: [ - // { - // path: '/account/center', - // redirect: '/account/center/articles', - // }, - // { - // path: '/account/center/articles', - // component: './Account/Center/Articles', - // }, - // { - // path: '/account/center/applications', - // component: './Account/Center/Applications', - // }, - // { - // path: '/account/center/projects', - // component: './Account/Center/Projects', - // }, - // ], }, { path: '/account/settings', name: 'settings', component: './Account/Settings/Info', - // routes: [ - // { - // path: '/account/settings', - // redirect: '/account/settings/base', - // }, - // { - // path: '/account/settings/base', - // component: './Account/Settings/BaseView', - // }, - // { - // path: '/account/settings/security', - // component: './Account/Settings/SecurityView', - // }, - // { - // path: '/account/settings/binding', - // component: './Account/Settings/BindingView', - // }, - // { - // path: '/account/settings/notification', - // component: './Account/Settings/NotificationView', - // }, - // ], }, ], }, @@ -284,6 +221,7 @@ module.exports = [ }, ], }, + { path: '/', redirect: '/dashboard/analysis', authority: ['admin', 'user'] }, { component: '404', }, diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index 8ce2d93a0eafad9802c5008f2f835d1177adefb3..4aaf0076b109f1e01fbd73edf093f02fa1cdc819 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -25,17 +25,13 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & { }; /** - * default menuLocal + * use Authorized check all menu item */ -const filterMenuData = (menuList: MenuDataItem[], locale: boolean): MenuDataItem[] => { +const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] => { return menuList.map(item => { const localItem = { ...item, - name: - item.locale && locale - ? formatMessage({ id: item.locale, defaultMessage: item.name }) - : item.name, - children: item.children ? filterMenuData(item.children, locale) : [], + children: item.children ? menuDataRender(item.children) : [], }; return Authorized.check(item.authority, localItem, null) as MenuDataItem; @@ -56,9 +52,7 @@ const BasicLayout: React.FC = props => { */ const handleMenuCollapse = (payload: boolean) => dispatch!({ type: 'global/changeLayoutCollapsed', payload }); - const { - menu: { locale }, - } = settings; + return ( <> = props => { menuItemRender={(menuItemProps, defaultDom) => { return {defaultDom}; }} - filterMenuData={menuList => filterMenuData(menuList, locale)} + breadcrumbRender={(routers = []) => { + return [ + { + path: '/', + breadcrumbName: formatMessage({ + id: 'menu.home', + defaultMessage: 'Home', + }), + }, + ...routers, + ]; + }} + menuDataRender={menuDataRender} + formatMessage={formatMessage} rightContentRender={rightProps => } {...props} {...settings} @@ -85,7 +92,7 @@ const BasicLayout: React.FC = props => { } /> )} - + ); };