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/mock/user.js b/src/mock/user.js index 21f7d08..0400d9b 100644 --- a/src/mock/user.js +++ b/src/mock/user.js @@ -25,15 +25,22 @@ let usersListData = Mock.mock({ let database = usersListData.data +const EnumRoleType = { + ADMIN: 'admin', + DEFAULT: 'admin', + DEVELOPER: 'developer', +} + const userPermission = { DEFAULT: { visit: ['1', '2', '21', '7', '5', '51', '52', '53'], + role: EnumRoleType.DEFAULT, }, ADMIN: { - visit: ['1', '2', '7', '21', '3', '4', '41', '42', '43', '44', '45', '46', '5', '51', '52', '53', '6', '61', '62', '621', '622'], + role: EnumRoleType.ADMIN, }, DEVELOPER: { - visit: ['1', '2', '7', '21', '3', '4', '41', '42', '43', '44', '45', '46', '5', '51', '52', '53', '6', '61', '62', '621', '622'], + role: EnumRoleType.DEVELOPER, }, } diff --git a/src/models/app.js b/src/models/app.js index fe0221c..49cb085 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -2,8 +2,8 @@ import { query, logout } from '../services/app' import * as menusService from '../services/menus' import { routerRedux } from 'dva/router' import { parse } from 'qs' -import { config } from 'utils' -const { prefix } = config +import { prefix } from 'config' +import { EnumRoleType } from 'enums' export default { namespace: 'app', @@ -55,6 +55,9 @@ export default { user, permissions, menu: list.filter(item => { + if (permissions.role === EnumRoleType.ADMIN || permissions.role === EnumRoleType.DEVELOPER) { + return true + } const cases = [ permissions.visit.includes(item.id), item.mpid ? permissions.visit.includes(item.mpid) || item.mpid === '-1' : true, 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/enums.js b/src/utils/enums.js new file mode 100644 index 0000000..69840fe --- /dev/null +++ b/src/utils/enums.js @@ -0,0 +1,9 @@ +const EnumRoleType = { + ADMIN: 'admin', + DEFAULT: 'admin', + DEVELOPER: 'developer', +} + +module.exports = { + EnumRoleType, +} 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', - }, -] diff --git a/webpack.config.js b/webpack.config.js index ebf868b..820fdd1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -29,6 +29,7 @@ module.exports = (webpackConfig) => { components: `${__dirname}/src/components`, utils: `${__dirname}/src/utils`, config: `${__dirname}/src/utils/config`, + enums: `${__dirname}/src/utils/enums`, } return webpackConfig