Commit 4332da74 authored by 张烨's avatar 张烨

feat: 🎸 merge menu config and route config, add authority check

parent b8e5f5a6
import React, { useState } from 'react'; import React, { useState } from 'react';
import check from '@/components/Authorized/CheckPermissions';
import { matchRoutes, renderRoutes } from 'react-router-config'; import { matchRoutes, renderRoutes } from 'react-router-config';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import ProLayout, { DefaultFooter } from '@ant-design/pro-layout'; import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';
import menuConfig from '../routes/menuConfig';
import logo from '../assets/images/logo/panda-logo.svg'; import logo from '../assets/images/logo/panda-logo.svg';
import RightContent from '../components/GlobalHeader/RightContent'; import RightContent from '../components/GlobalHeader/RightContent';
...@@ -26,15 +25,19 @@ const defaultFooterDom = ( ...@@ -26,15 +25,19 @@ const defaultFooterDom = (
/> />
); );
const userMode = localStorage.getItem('userMode');
if (userMode === 'common') {
menuConfig.shift();
}
const BasicLayout = props => { const BasicLayout = props => {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
const [pathname, setPathname] = useState('/welcome'); const [pathname, setPathname] = useState('/welcome');
const filterMenu = menuRoutes =>
menuRoutes
.map(route => {
if (route.routes) route.routes = filterMenu(route.routes);
return route.hideMenu ||
(route.authority && !check(route.authority, true, false))
? null
: route;
})
.filter(Boolean);
const handleMenuCollapse = () => {}; // get children authority const handleMenuCollapse = () => {}; // get children authority
matchRoutes(props.route.routes, props.location.pathname); matchRoutes(props.route.routes, props.location.pathname);
return ( return (
...@@ -56,7 +59,7 @@ const BasicLayout = props => { ...@@ -56,7 +59,7 @@ const BasicLayout = props => {
location={{ location={{
pathname, pathname,
}} }}
menuDataRender={() => menuConfig} menuDataRender={() => filterMenu(props.route.routes)}
menuItemRender={(menuItemProps, defaultDom) => { menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || !menuItemProps.path) { if (menuItemProps.isUrl || !menuItemProps.path) {
return defaultDom; return defaultDom;
......
import check from '@/components/Authorized/CheckPermissions';
import React from 'react'; import React from 'react';
import { renderRoutes } from 'react-router-config';
const Layout = ({ children }) => <>{children}</>; const Layout = ({ children, route }) => (
<>
{children ||
renderRoutes(
route.routes.filter(
r => !r.authority || check(r.authority, true, false),
),
)}
</>
);
export default Layout; export default Layout;
import React from 'react';
import {
DatabaseOutlined,
UsergroupAddOutlined,
SettingOutlined,
HomeOutlined,
// AndroidOutlined,
// CommentOutlined,
CopyOutlined,
} from '@ant-design/icons';
import UserLayout from '../layouts/UserLayout'; import UserLayout from '../layouts/UserLayout';
import Login from '../pages/user/login'; import Login from '../pages/user/login';
import BasicLayout from '../layouts/BasicLayout'; import BasicLayout from '../layouts/BasicLayout';
import BlankLayout from '../layouts/BlankLayout';
import Welcome from '../pages/Welcome'; import Welcome from '../pages/Welcome';
import RequestTest from '../pages/testPages/request'; import RequestTest from '../pages/testPages/request';
import InitDataBase from '../pages/database/InitDataBase'; import InitDataBase from '../pages/database/InitDataBase';
...@@ -10,11 +21,13 @@ import RoleManage from '../pages/userCenter/RoleManage'; ...@@ -10,11 +21,13 @@ import RoleManage from '../pages/userCenter/RoleManage';
import SiteManage from '../pages/userCenter/SiteManage'; import SiteManage from '../pages/userCenter/SiteManage';
// import DefaultComponent from '../pages/orgnazation/DefaultComponent'; // import DefaultComponent from '../pages/orgnazation/DefaultComponent';
import TestTable from '../pages/orgnazation/TestTable'; import TestTable from '../pages/orgnazation/TestTable';
const iconStyle = { verticalAlign: '0.125em' };
export default { export default {
routes: [ routes: [
{ {
path: '/user', path: '/user',
component: UserLayout, component: UserLayout,
hideMenu: true,
routes: [ routes: [
{ {
name: 'login', name: 'login',
...@@ -25,6 +38,7 @@ export default { ...@@ -25,6 +38,7 @@ export default {
}, },
{ {
path: '/test/request', path: '/test/request',
hideMenu: true,
component: RequestTest, component: RequestTest,
}, },
{ {
...@@ -32,104 +46,146 @@ export default { ...@@ -32,104 +46,146 @@ export default {
component: BasicLayout, component: BasicLayout,
routes: [ routes: [
{ {
path: '/dbm/dbInit', path: '/dbm',
name: '数据库初始化', name: '数据库管理',
component: InitDataBase, icon: <DatabaseOutlined style={iconStyle} />,
}, component: BlankLayout,
{ routes: [
path: '/dbm/dbsm', {
name: '数据库标准化管理', path: '/dbm/dbInit',
component: ManagementDataBase, name: '数据库初始化',
}, component: InitDataBase,
{ },
path: '/userCenter/UserManage', {
name: '用户管理', path: '/dbm/dbsm',
component: UserManage, name: '数据库标准化管理',
}, component: ManagementDataBase,
{ },
path: '/userCenter/RoleManage', ],
name: '角色管理', },
component: RoleManage, {
}, path: '/userCenter',
{ name: '用户中心',
path: '/userCenter/SiteManage', component: BlankLayout,
name: '站点管理', icon: <UsergroupAddOutlined style={iconStyle} />,
component: SiteManage, routes: [
{
path: '/userCenter/UserManage',
name: '用户管理',
component: UserManage,
},
{
path: '/userCenter/RoleManage',
name: '角色管理',
component: RoleManage,
},
{
path: '/userCenter/SiteManage',
name: '站点管理',
component: SiteManage,
},
],
}, },
{ {
path: '/userCenter/testTable', path: '/userCenter/testTable',
name: '测试表格', name: '测试表格',
hideMenu: true,
component: TestTable, component: TestTable,
}, },
{ {
path: '/platformCenter/gis', path: '/platformCenter',
name: 'GIS平台', component: BlankLayout,
component: Welcome, name: '平台中心',
}, icon: <SettingOutlined style={iconStyle} />,
{ routes: [
path: '/platformCenter/order', {
name: '工单平台', path: '/platformCenter/gis',
component: Welcome, name: 'GIS平台',
}, component: Welcome,
{ },
path: '/platformCenter/notify', {
name: '消息平台', path: '/platformCenter/order',
component: Welcome, name: '工单平台',
}, component: Welcome,
{ },
path: '/platformCenter/vedio', {
name: '视频管理', path: '/platformCenter/notify',
component: Welcome, name: '消息平台',
}, component: Welcome,
{ },
path: '/platformCenter/emq', {
name: '宿主管理', path: '/platformCenter/vedio',
component: Welcome, name: '视频管理',
}, component: Welcome,
{ },
path: '/platformCenter/dictionary', {
name: '数据字典', path: '/platformCenter/emq',
component: Welcome, name: '宿主管理',
}, component: Welcome,
{ },
path: '/productCenter/web', {
name: 'web配置', path: '/platformCenter/dictionary',
component: Welcome, name: '数据字典',
}, component: Welcome,
{ },
path: '/productCenter/app', ],
name: 'app配置', },
component: Welcome, {
}, path: '/productCenter',
{ component: BlankLayout,
path: '/productCenter/miniProgram', name: '产品中心',
name: '小程序配置', icon: <HomeOutlined style={iconStyle} />,
component: Welcome, routes: [
{
path: '/productCenter/web',
name: 'web配置',
component: Welcome,
},
{
path: '/productCenter/app',
name: 'app配置',
component: Welcome,
},
{
path: '/productCenter/miniProgram',
name: '小程序配置',
component: Welcome,
},
],
}, },
{ {
path: '/log', path: '/log',
component: BlankLayout,
name: '日志管理', name: '日志管理',
component: Welcome, icon: <CopyOutlined style={iconStyle} />,
}, routes: [
{ {
path: '/log/service', path: '/log',
name: '服务日志', name: '日志管理',
component: Welcome, icon: <CopyOutlined style={iconStyle} />,
}, component: Welcome,
{ },
path: '/log/login', {
name: '登录日志', path: '/log/service',
component: Welcome, name: '服务日志',
}, component: Welcome,
{ },
path: '/log/omsOperation', {
name: '运维操作日志', path: '/log/login',
component: Welcome, name: '登录日志',
}, component: Welcome,
{ },
path: '/log/omsError', {
name: '运维错误日志', path: '/log/omsOperation',
component: Welcome, name: '运维操作日志',
component: Welcome,
},
{
path: '/log/omsError',
name: '运维错误日志',
component: Welcome,
},
],
}, },
], ],
}, },
......
import React from 'react';
import {
DatabaseOutlined,
UsergroupAddOutlined,
SettingOutlined,
HomeOutlined,
// AndroidOutlined,
// CommentOutlined,
CopyOutlined,
} from '@ant-design/icons';
const iconStyle = { verticalAlign: '0.125em' };
const menuConfig = [
{
path: '/dbm',
component: 'BasicLayout',
name: '数据库管理',
icon: <DatabaseOutlined style={iconStyle} />,
routes: [
{
path: '/dbm/dbInit',
name: '数据库初始化',
},
{
path: '/dbm/dbsm',
name: '数据库标准化管理',
},
],
},
{
path: '/userCenter',
component: 'BasicLayout',
name: '用户中心',
icon: <UsergroupAddOutlined style={iconStyle} />,
routes: [
{
path: '/userCenter/UserManage',
name: '用户管理',
},
{
path: '/userCenter/RoleManage',
name: '角色管理',
},
{
path: '/userCenter/SiteManage',
name: '站点管理',
},
],
},
{
path: '/platformCenter',
component: 'BasicLayout',
name: '平台中心',
icon: <SettingOutlined style={iconStyle} />,
routes: [
{
path: '/platformCenter/gis',
name: 'GIS平台',
},
{
path: '/platformCenter/order',
name: '工单平台',
},
{
path: '/platformCenter/notify',
name: '消息平台',
},
{
path: '/platformCenter/iot',
name: '物联平台',
},
{
path: '/platformCenter/vedio',
name: '视频管理',
},
{
path: '/platformCenter/emq',
name: '宿主管理',
},
{
path: '/platformCenter/dictionary',
name: '数据字典',
},
],
},
{
path: '/productCenter',
component: 'BasicLayout',
name: '产品中心',
icon: <HomeOutlined style={iconStyle} />,
routes: [
{
path: '/productCenter/web',
name: 'web配置',
},
{
path: '/productCenter/app',
name: 'app配置',
},
{
path: '/productCenter/miniProgram',
name: '小程序配置',
},
],
},
{
path: '/log',
component: 'BasicLayout',
name: '日志管理',
icon: <CopyOutlined style={iconStyle} />,
routes: [
{
path: '/log/service',
name: '服务日志',
},
{
path: '/log/login',
name: '登录日志',
},
{
path: '/log/omsOperation',
name: '运维操作日志',
},
{
path: '/log/omsError',
name: '运维错误日志',
},
],
},
];
export default menuConfig;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment