From b0816a4c35cbdffdf6f2824eafa2a7b792c198db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=84=9A=E9=81=93?= Date: Thu, 23 Aug 2018 12:24:06 +0800 Subject: [PATCH] fix: remove unnecessary files --- src/common/menu.js | 152 ---------------- src/common/router.js | 343 ----------------------------------- src/locales/localeContext.js | 53 ------ src/router.js | 31 ---- 4 files changed, 579 deletions(-) delete mode 100644 src/common/menu.js delete mode 100644 src/common/router.js delete mode 100644 src/locales/localeContext.js delete mode 100644 src/router.js diff --git a/src/common/menu.js b/src/common/menu.js deleted file mode 100644 index bccbae72..00000000 --- a/src/common/menu.js +++ /dev/null @@ -1,152 +0,0 @@ -// // TODO: authority -// const menuData = [ -// { -// name: 'dashboard', -// icon: 'dashboard', -// path: 'dashboard', -// children: [ -// { -// name: 'analysis', -// path: 'analysis', -// }, -// { -// name: 'monitor', -// path: 'monitor', -// }, -// { -// name: 'workplace', -// path: 'workplace', -// // hideInBreadcrumb: true, -// // hideInMenu: true, -// }, -// ], -// }, -// { -// name: 'form', -// icon: 'form', -// path: 'form', -// children: [ -// { -// name: 'basicform', -// path: 'basic-form', -// }, -// { -// name: 'stepform', -// path: 'step-form', -// }, -// { -// // authority: 'admin', -// name: 'advancedform', -// authority: 'admin', -// path: 'advanced-form', -// }, -// ], -// }, -// { -// name: 'list', -// icon: 'table', -// path: 'list', -// children: [ -// { -// name: 'searchlist', -// path: 'table-list', -// }, -// { -// name: 'basiclist', -// path: 'basic-list', -// }, -// { -// name: 'cardlist', -// path: 'card-list', -// }, -// { -// name: 'searchlist', -// path: 'search', -// children: [ -// { -// name: 'articles', -// path: 'articles', -// }, -// { -// name: 'projects', -// path: 'projects', -// }, -// { -// name: 'applications', -// path: 'applications', -// }, -// ], -// }, -// ], -// }, -// { -// name: 'profile', -// icon: 'profile', -// path: 'profile', -// children: [ -// { -// name: 'basic', -// path: 'basic', -// }, -// { -// name: 'advanced', -// path: 'advanced', -// // authority: 'admin', -// }, -// ], -// }, -// { -// name: 'result', -// icon: 'check-circle-o', -// path: 'result', -// children: [ -// { -// name: 'success', -// path: 'success', -// }, -// { -// name: 'fail', -// path: 'fail', -// }, -// ], -// }, -// { -// name: 'exception', -// icon: 'warning', -// path: 'exception', -// children: [ -// { -// name: 'not-permission', -// path: '403', -// }, -// { -// name: 'not-find', -// path: '404', -// }, -// { -// name: 'server-error', -// path: '500', -// }, -// { -// name: 'trigger', -// path: 'trigger', -// hideInMenu: true, -// }, -// ], -// }, -// { -// name: 'account', -// icon: 'user', -// path: 'account', -// children: [ -// { -// name: 'center', -// path: 'center', -// }, -// { -// name: 'settings', -// path: 'settings', -// }, -// ], -// }, -// ]; diff --git a/src/common/router.js b/src/common/router.js deleted file mode 100644 index 3524efa7..00000000 --- a/src/common/router.js +++ /dev/null @@ -1,343 +0,0 @@ -// TODO:remove -// import { createElement } from 'react'; -// import dynamic from 'dva/dynamic'; -// import pathToRegexp from 'path-to-regexp'; -// import { getMenuData } from './menu'; - -// let routerDataCache; - -// const modelNotExisted = (app, model) => -// // eslint-disable-next-line -// !app._models.some(({ namespace }) => { -// return namespace === model.substring(model.lastIndexOf('/') + 1); -// }); - -// // wrapper of dynamic -// const dynamicWrapper = (app, models, component) => { -// // () => require('module') -// // transformed by babel-plugin-dynamic-import-node-sync -// if (component.toString().indexOf('.then(') < 0) { -// models.forEach(model => { -// if (modelNotExisted(app, model)) { -// // eslint-disable-next-line -// app.model(require(`../models/${model}`).default); -// } -// }); -// return props => { -// if (!routerDataCache) { -// routerDataCache = getRouterData(app); -// } -// return createElement(component().default, { -// ...props, -// routerData: routerDataCache, -// }); -// }; -// } -// // () => import('module') -// return dynamic({ -// app, -// models: () => -// models.filter(model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`)), -// // add routerData prop -// component: () => { -// if (!routerDataCache) { -// routerDataCache = getRouterData(app); -// } -// return component().then(raw => { -// const Component = raw.default || raw; -// return props => -// createElement(Component, { -// ...props, -// routerData: routerDataCache, -// }); -// }); -// }, -// }); -// }; - -// function getFlatMenuData(menus) { -// let keys = {}; -// menus.forEach(item => { -// if (item.children) { -// keys[item.path] = { ...item }; -// keys = { ...keys, ...getFlatMenuData(item.children) }; -// } else { -// keys[item.path] = { ...item }; -// } -// }); -// return keys; -// } - -// export const getRouterData = app => { -// const routerConfig = { -// '/': { -// component: dynamicWrapper(app, ['user', 'login', 'setting'], () => -// import('../layouts/LoadingPage') -// ), -// }, -// '/dashboard/analysis': { -// component: dynamicWrapper(app, ['chart'], () => import('../pages/Dashboard/Analysis')), -// }, -// '/dashboard/monitor': { -// component: dynamicWrapper(app, ['monitor'], () => import('../pages/Dashboard/Monitor')), -// }, -// '/dashboard/workplace': { -// component: dynamicWrapper(app, ['user', 'project', 'activities', 'chart'], () => -// import('../pages/Dashboard/Workplace') -// ), -// // hideInBreadcrumb: true, -// // name: '工作台', -// // authority: 'admin', -// }, -// '/form/basic-form': { -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/BasicForm')), -// }, -// '/form/step-form': { -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/StepForm')), -// }, -// '/form/step-form/info': { -// name: '分步表单(填写转账信息)', -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/StepForm/Step1')), -// }, -// '/form/step-form/confirm': { -// name: '分步表单(确认转账信息)', -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/StepForm/Step2')), -// }, -// '/form/step-form/result': { -// name: '分步表单(完成)', -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/StepForm/Step3')), -// }, -// '/form/advanced-form': { -// component: dynamicWrapper(app, ['form'], () => import('../pages/Forms/AdvancedForm')), -// }, -// '/list/table-list': { -// component: dynamicWrapper(app, ['rule'], () => import('../pages/List/TableList')), -// }, -// '/list/basic-list': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/BasicList')), -// }, -// '/list/card-list': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/CardList')), -// }, -// '/list/search': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/List')), -// }, -// '/list/search/projects': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/Projects')), -// }, -// '/list/search/applications': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/Applications')), -// }, -// '/list/search/articles': { -// component: dynamicWrapper(app, ['list'], () => import('../pages/List/Articles')), -// }, -// '/profile/basic': { -// component: dynamicWrapper(app, ['profile'], () => import('../pages/Profile/BasicProfile')), -// }, -// '/profile/advanced': { -// component: dynamicWrapper(app, ['profile'], () => import('../pages/Profile/AdvancedProfile')), -// }, -// '/result/success': { -// component: dynamicWrapper(app, [], () => import('../pages/Result/Success')), -// }, -// '/result/fail': { -// component: dynamicWrapper(app, [], () => import('../pages/Result/Error')), -// }, -// '/exception/403': { -// component: dynamicWrapper(app, [], () => import('../pages/Exception/403')), -// }, -// '/exception/404': { -// component: dynamicWrapper(app, [], () => import('../pages/Exception/404')), -// }, -// '/exception/500': { -// component: dynamicWrapper(app, [], () => import('../pages/Exception/500')), -// }, -// '/exception/trigger': { -// component: dynamicWrapper(app, ['error'], () => -// import('../pages/Exception/triggerException') -// ), -// }, -// '/user': { -// component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')), -// }, -// '/user/login': { -// component: dynamicWrapper(app, ['login'], () => import('../pages/User/Login')), -// }, -// '/user/register': { -// component: dynamicWrapper(app, ['register'], () => import('../pages/User/Register')), -// }, -// '/user/register-result': { -// component: dynamicWrapper(app, [], () => import('../pages/User/RegisterResult')), -// }, -// '/account/center': { -// component: dynamicWrapper(app, ['list', 'user', 'project'], () => -// import('../pages/Account/Center/Center') -// ), -// }, -// '/account/center/articles': { -// component: dynamicWrapper(app, [], () => import('../pages/Account/Center/Articles')), -// }, -// '/account/center/applications': { -// component: dynamicWrapper(app, [], () => import('../pages/Account/Center/Applications')), -// }, -// '/account/center/projects': { -// component: dynamicWrapper(app, [], () => import('../pages/Account/Center/Projects')), -// }, -// '/account/settings': { -// component: dynamicWrapper(app, ['geographic'], () => -// import('../pages/Account/Settings/Info') -// ), -// }, -// '/account/settings/base': { -// component: dynamicWrapper(app, ['geographic'], () => -// import('../pages/Account/Settings/BaseView') -// ), -// }, -// '/account/settings/security': { -// component: dynamicWrapper(app, ['geographic'], () => -// import('../pages/Account/Settings/SecurityView') -// ), -// }, -// '/account/settings/binding': { -// component: dynamicWrapper(app, ['geographic'], () => -// import('../pages/Account/Settings/BindingView') -// ), -// }, -// '/account/settings/notification': { -// component: dynamicWrapper(app, ['geographic'], () => -// import('../pages/Account/Settings/NotificationView') -// ), -// }, -// // '/user/:id': { -// // component: dynamicWrapper(app, [], () => import('../pages/User/SomeComponent')), -// // }, -// }; -// // Get name from ./menu.js or just set it in the router data. -// const menuData = getFlatMenuData(getMenuData()); - -// // Route configuration data -// // eg. {name,authority ...routerConfig } -// const routerData = {}; -// // The route matches the menu -// Object.keys(routerConfig).forEach(path => { -// // Regular match item name -// // eg. router /user/:id === /user/chen -// const pathRegexp = pathToRegexp(path); -// const menuKey = Object.keys(menuData).find(key => pathRegexp.test(`${key}`)); -// let menuItem = {}; -// // If menuKey is not empty -// if (menuKey) { -// menuItem = menuData[menuKey]; -// } -// let router = routerConfig[path]; -// // If you need to configure complex parameter routing, -// // https://github.com/ant-design/ant-design-pro-site/blob/master/docs/router-and-nav.md#%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E8%B7%AF%E7%94%B1%E8%8F%9C%E5%8D%95 -// // eg . /list/:type/user/info/:id -// router = { -// ...router, -// name: router.name || menuItem.name, -// authority: router.authority || menuItem.authority, -// hideInBreadcrumb: router.hideInBreadcrumb || menuItem.hideInBreadcrumb, -// }; -// routerData[path] = router; -// }); -// return routerData; -// }; - -import pathToRegexp from 'path-to-regexp'; -import { getMenuData } from './menu'; - -function getFlatMenuData(menus) { - let keys = {}; - menus.forEach(item => { - if (item.children) { - keys[item.path] = { ...item }; - keys = { ...keys, ...getFlatMenuData(item.children) }; - } else { - keys[item.path] = { ...item }; - } - }); - return keys; -} - -export const getRouterData = () => { - const routerConfig = { - '/': { - name: 'Ant-Design-Pro', - }, - '/Dashboard/Analysis': { - name: '分析页', - }, - '/Dashboard/Monitor': {}, - '/Dashboard/Workplace': { - // component: dynamicWrapper(app, ['project', 'activities', 'chart'], () => import('../routes/Dashboard/Workplace')), - // hideInBreadcrumb: true, - // name: '工作台', - // authority: 'admin', - }, - '/Forms/BasicForm': {}, - '/Forms/StepForm': {}, - '/Forms/StepForm/Step1': { - name: '分步表单(填写转账信息)', - }, - '/Forms/StepForm/Step2': { - name: '分步表单(确认转账信息)', - }, - '/Forms/StepForm/Step3': { - name: '分步表单(完成)', - }, - '/Forms/AdvancedForm': {}, - '/List/TableList': {}, - '/List/BasicList': {}, - '/List/CardList': {}, - '/List': {}, - '/List/Search/Projects': {}, - '/List/Search/Applications': {}, - '/List/Search/Articles': {}, - '/Profile/BasicProfile': {}, - '/Profile/AdvancedProfile': {}, - '/Result/success': {}, - '/Result/Error': {}, - '/Exception/403': {}, - '/Exception/404': {}, - '/Exception/500': {}, - '/Exception/triggerException': {}, - '/User': {}, - '/User/Login': {}, - '/User/Register': {}, - '/User/RegisterResult': {}, - // '/user/:id': { - // component: dynamicWrapper(app, [], () => console.log('../routes/User/SomeComponent')), - // }, - }; - // Get name from ./menu.js or just set it in the router data. - const menuData = getFlatMenuData(getMenuData()); - - // Route configuration data - // eg. {name,authority ...routerConfig } - const routerData = {}; - // The route matches the menu - Object.keys(routerConfig).forEach(path => { - // Regular match item name - // eg. router /user/:id === /user/chen - const pathRegexp = pathToRegexp(path); - const menuKey = Object.keys(menuData).find(key => pathRegexp.test(`${key}`)); - let menuItem = {}; - // If menuKey is not empty - if (menuKey) { - menuItem = menuData[menuKey]; - } - let router = routerConfig[path]; - // If you need to configure complex parameter routing, - // https://github.com/ant-design/ant-design-pro-site/blob/master/docs/router-and-nav.md#%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E8%B7%AF%E7%94%B1%E8%8F%9C%E5%8D%95 - // eg . /list/:type/user/info/:id - router = { - ...router, - name: router.name || menuItem.name, - authority: router.authority || menuItem.authority, - }; - routerData[path] = router; - }); - - return routerData; -}; diff --git a/src/locales/localeContext.js b/src/locales/localeContext.js deleted file mode 100644 index 6f848dbb..00000000 --- a/src/locales/localeContext.js +++ /dev/null @@ -1,53 +0,0 @@ -import React from 'react'; -import { addLocaleData, IntlProvider } from 'umi/locale'; -import { LocaleProvider } from 'antd'; -import enLocale from './en-US'; -import cnLocale from './zh-CN'; - -const Context = React.createContext(); - -function getLang() { - if (window.localStorage && localStorage.getItem('locale')) { - return localStorage.getItem('locale'); - } - return (navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us' - ? 'en-US' - : 'zh-CN'; -} - -export class LocalComponent extends React.PureComponent { - state = { - locale: getLang(), - }; - - changeLocal = () => { - this.setState({ - locale: getLang(), - }); - }; - - render() { - const { children } = this.props; - const { locale } = this.state; - return ( - - - {({ appLocale }) => { - addLocaleData(appLocale.data); - return ( - - {children} - - ); - }} - - - ); - } -} -export default Context; diff --git a/src/router.js b/src/router.js deleted file mode 100644 index 36166bd2..00000000 --- a/src/router.js +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react'; -import { routerRedux, Route, Switch } from 'dva/router'; -import { getRouterData } from './common/router'; -import Authorized from './utils/Authorized'; -import { getQueryPath } from './utils/utils'; - -const { ConnectedRouter } = routerRedux; -const { AuthorizedRoute } = Authorized; - -function RouterConfig({ history, app }) { - const routerData = getRouterData(app); - const UserLayout = routerData['/user'].component; - const BasicLayout = routerData['/'].component; - return ( - - - - } - authority={['admin', 'user']} - redirectPath={getQueryPath('/user/login', { - redirect: window.location.href, - })} - /> - - - ); -} - -export default RouterConfig; -- GitLab