From f113fbb238a110a19945bd286eb857c416ddc042 Mon Sep 17 00:00:00 2001 From: zuiidea Date: Wed, 5 Jul 2017 19:29:14 +0800 Subject: [PATCH] revise menu property : router => route --- src/components/Layout/Bread.js | 4 +- src/components/Layout/Menu.js | 4 +- src/mock/menu.js | 38 ++++---- src/routes/app.js | 2 +- src/utils/index.js | 2 - src/utils/menu.js | 154 --------------------------------- 6 files changed, 24 insertions(+), 180 deletions(-) delete mode 100644 src/utils/menu.js diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index 21aa00f..0430d38 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -11,7 +11,7 @@ const Bread = ({ menu }) => { let pathArray = [] let current for (let index in menu) { - if (menu[index].router && pathToRegexp(menu[index].router).exec(location.pathname)) { + if (menu[index].route && pathToRegexp(menu[index].route).exec(location.pathname)) { current = menu[index] break } @@ -48,7 +48,7 @@ const Bread = ({ menu }) => { return ( {((pathArray.length - 1) !== key) - ? + ? {content} : content} diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 121e2f4..ad02c0a 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -31,7 +31,7 @@ const Menus = ({ siderFold, darkTheme, handleClickNavMenu, navOpenKeys, changeOp } return ( - + {item.icon && } {(!siderFoldN || !menuTree.includes(item)) && item.name} @@ -82,7 +82,7 @@ const Menus = ({ siderFold, darkTheme, handleClickNavMenu, navOpenKeys, changeOp let currentMenu let defaultSelectedKeys for (let item of menu) { - if (item.router && pathToRegexp(item.router).exec(location.pathname)) { + if (item.route && pathToRegexp(item.route).exec(location.pathname)) { currentMenu = item break } diff --git a/src/mock/menu.js b/src/mock/menu.js index c839d84..577e3b5 100644 --- a/src/mock/menu.js +++ b/src/mock/menu.js @@ -1,4 +1,4 @@ -const { config, posts } = require('./common') +const { config } = require('./common') const { apiPrefix } = config let database = [ @@ -6,35 +6,35 @@ let database = [ id: '1', icon: 'laptop', name: 'Dashboard', - router: '/dashboard', + route: '/dashboard', }, { id: '2', bpid: '1', name: 'Users', icon: 'user', - router: '/user', + route: '/user', }, { id: '7', bpid: '1', name: 'Posts', icon: 'shopping-cart', - router: '/post', + route: '/post', }, { id: '21', mpid: '-1', bpid: '2', name: 'User Detail', - router: '/user/:id', + route: '/user/:id', }, { id: '3', bpid: '1', name: 'Request', icon: 'api', - router: '/request', + route: '/request', }, { id: '4', @@ -48,7 +48,7 @@ let database = [ mpid: '4', name: 'IconFont', icon: 'heart-o', - router: '/UIElement/iconfont', + route: '/UIElement/iconfont', }, { id: '42', @@ -56,7 +56,7 @@ let database = [ mpid: '4', name: 'DataTable', icon: 'database', - router: '/UIElement/dataTable', + route: '/UIElement/dataTable', }, { id: '43', @@ -64,7 +64,7 @@ let database = [ mpid: '4', name: 'DropOption', icon: 'bars', - router: '/UIElement/dropOption', + route: '/UIElement/dropOption', }, { id: '44', @@ -72,7 +72,7 @@ let database = [ mpid: '4', name: 'Search', icon: 'search', - router: '/UIElement/search', + route: '/UIElement/search', }, { id: '45', @@ -80,7 +80,7 @@ let database = [ mpid: '4', name: 'Editor', icon: 'edit', - router: '/UIElement/editor', + route: '/UIElement/editor', }, { id: '46', @@ -88,7 +88,7 @@ let database = [ mpid: '4', name: 'layer (Function)', icon: 'credit-card', - router: '/UIElement/layer', + route: '/UIElement/layer', }, { id: '5', @@ -102,7 +102,7 @@ let database = [ mpid: '5', name: 'LineChart', icon: 'line-chart', - router: '/chart/lineChart', + route: '/chart/lineChart', }, { id: '52', @@ -110,7 +110,7 @@ let database = [ mpid: '5', name: 'BarChart', icon: 'bar-chart', - router: '/chart/barChart', + route: '/chart/barChart', }, { id: '53', @@ -118,7 +118,7 @@ let database = [ mpid: '5', name: 'AreaChart', icon: 'area-chart', - router: '/chart/areaChart', + route: '/chart/areaChart', }, { id: '6', @@ -131,28 +131,28 @@ let database = [ bpid: '6', mpid: '6', name: 'Test Navigation1', - router: '/navigation/navigation1', + route: '/navigation/navigation1', }, { id: '62', bpid: '6', mpid: '6', name: 'Test Navigation2', - router: '/navigation/navigation2', + route: '/navigation/navigation2', }, { id: '621', bpid: '62', mpid: '62', name: 'Test Navigation21', - router: '/navigation/navigation2/navigation1', + route: '/navigation/navigation2/navigation1', }, { id: '622', bpid: '62', mpid: '62', name: 'Test Navigation22', - router: '/navigation/navigation2/navigation2', + route: '/navigation/navigation2/navigation2', }, ] diff --git a/src/routes/app.js b/src/routes/app.js index 087c5bb..618be82 100644 --- a/src/routes/app.js +++ b/src/routes/app.js @@ -19,7 +19,7 @@ const App = ({ children, dispatch, app, loading, location }) => { let { pathname } = location pathname = pathname.startsWith('/') ? pathname : `/${pathname}` const { iconFontJS, iconFontCSS, logo } = config - const current = menu.filter(item => pathToRegexp(item.router || '').exec(pathname)) + const current = menu.filter(item => pathToRegexp(item.route || '').exec(pathname)) const hasPermission = current.length ? permissions.visit.includes(current[0].id) : false const href = window.location.href diff --git a/src/utils/index.js b/src/utils/index.js index 52e5c08..9c67951 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,4 @@ import config from './config' -import menu from './menu' import request from './request' import classnames from 'classnames' import { color } from './theme' @@ -101,7 +100,6 @@ const arrayToTree = (array, id = 'id', pid = 'pid', children = 'children') => { module.exports = { config, - menu, request, color, classnames, diff --git a/src/utils/menu.js b/src/utils/menu.js deleted file mode 100644 index 9242b9e..0000000 --- a/src/utils/menu.js +++ /dev/null @@ -1,154 +0,0 @@ -module.exports = [ - { - id: 1, - icon: 'laptop', - name: 'Dashboard', - router: '/dashboard', - }, - { - id: 2, - bpid: 1, - name: 'Users', - icon: 'user', - router: '/user', - }, - { - id: 7, - bpid: 1, - name: 'Posts', - icon: 'shopping-cart', - router: '/post', - }, - { - id: 21, - mpid: -1, - bpid: 2, - name: 'User Detail', - router: '/user/:id', - }, - { - id: 3, - bpid: 1, - name: 'Request', - icon: 'api', - router: '/request', - }, - { - id: 4, - bpid: 1, - name: 'UI Element', - icon: 'camera-o', - }, - { - id: 41, - bpid: 4, - mpid: 4, - name: 'IconFont', - icon: 'heart-o', - router: '/UIElement/iconfont', - }, - { - id: 42, - bpid: 4, - mpid: 4, - name: 'DataTable', - icon: 'database', - router: '/UIElement/dataTable', - }, - { - id: 43, - bpid: 4, - mpid: 4, - name: 'DropOption', - icon: 'bars', - router: '/UIElement/dropOption', - }, - { - id: 44, - bpid: 4, - mpid: 4, - name: 'Search', - icon: 'search', - router: '/UIElement/search', - }, - { - id: 45, - bpid: 4, - mpid: 4, - name: 'Editor', - icon: 'edit', - router: '/UIElement/editor', - }, - { - id: 46, - bpid: 4, - mpid: 4, - name: 'layer (Function)', - icon: 'credit-card', - router: '/UIElement/layer', - }, - { - id: 5, - bpid: 1, - name: 'Recharts', - icon: 'code-o', - }, - { - id: 51, - bpid: 5, - mpid: 5, - name: 'LineChart', - icon: 'line-chart', - router: '/chart/lineChart', - }, - { - id: 52, - bpid: 5, - mpid: 5, - name: 'BarChart', - icon: 'bar-chart', - router: '/chart/barChart', - }, - { - id: 53, - bpid: 5, - mpid: 5, - name: 'AreaChart', - icon: 'area-chart', - router: '/chart/areaChart', - }, - { - id: 6, - bpid: 1, - name: 'Test Navigation', - icon: 'setting', - }, - { - id: 61, - bpid: 6, - mpid: 6, - name: 'Test Navigation1', - router: '/navigation/navigation1', - }, - { - id: 62, - bpid: 6, - mpid: 6, - name: 'Test Navigation2', - router: '/navigation/navigation2', - }, - { - id: 621, - bpid: 62, - mpid: 62, - name: 'Test Navigation21', - router: '/navigation/navigation2/navigation1', - }, - { - id: 622, - bpid: 62, - mpid: 62, - name: 'Test Navigation22', - router: '/navigation/navigation2/navigation2', - }, -]