Commit da40eadf authored by 陈前坚's avatar 陈前坚

添加登录权限控制,静态菜单

parent e59c081d
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { import { matchRoutes, renderRoutes } from 'react-router-config';
matchRoutes,
renderRoutes,
} from 'react-router-config';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { GithubOutlined } from '@ant-design/icons'; import { GithubOutlined } from '@ant-design/icons';
...@@ -11,7 +9,7 @@ import ProLayout, { DefaultFooter } from '@ant-design/pro-layout'; ...@@ -11,7 +9,7 @@ import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';
import logo from '../assets/logo.svg'; import logo from '../assets/logo.svg';
import RightContent from '../components/GlobalHeader/RightContent'; import RightContent from '../components/GlobalHeader/RightContent';
import config from '../routes/config'; // import config from '../routes/config';
// const noMatch = ( // const noMatch = (
// <Result // <Result
...@@ -47,9 +45,96 @@ const defaultFooterDom = ( ...@@ -47,9 +45,96 @@ const defaultFooterDom = (
]} ]}
/> />
); );
const BasicMenu = [
{
path: '/dbm',
component: 'BasicLayout',
name: '数据库管理',
icon: 'icon-dashboard',
routes: [
{
path: '/dbm/dbInit',
name: '数据库初始化',
},
{
path: '/dbm/dbsm',
name: '数据库标准化管理',
},
],
},
{
path: '/ou',
component: 'BasicLayout',
name: '机构与用户管理',
icon: 'icon-dashboard',
routes: [
{
path: '/ou/orgList',
name: '机构列表',
},
],
},
{
path: '/basicConfig',
component: 'BasicLayout',
name: '基础通用配置',
icon: 'icon-dashboard',
},
{
path: '/web5',
component: 'BasicLayout',
name: 'Web5配置',
icon: 'icon-dashboard',
},
{
path: '/app',
component: 'BasicLayout',
name: '手持系统配置',
icon: 'icon-dashboard',
},
{
path: '/miniPro',
component: 'BasicLayout',
name: '小程序配置',
authority: ['admin', 'user'],
icon: 'icon-dashboard',
},
{
path: '/log',
component: 'BasicLayout',
name: '日志管理',
icon: 'icon-dashboard',
routes: [
{
path: '/log/service',
name: '服务日志',
},
{
path: '/log/login',
name: '登录日志',
},
],
},
];
const basicUrl = 'http://localhost:8080/Cityinterface/rest/services/OMS.svc/';
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 [menuData, setMenuData] = useState([]);
console.log(props);
useEffect(() => {
fetch(`${basicUrl}U_GetOUTree?_version=9999`)
.then(response => response.json())
.then(data => {
const userMode = localStorage.getItem('userMode');
if (userMode == 'common') {
BasicMenu.shift();
}
setMenuData(BasicMenu || []);
});
}, []);
const handleMenuCollapse = () => {}; // get children authority const handleMenuCollapse = () => {}; // get children authority
matchRoutes(props.route.routes, props.location.pathname); matchRoutes(props.route.routes, props.location.pathname);
...@@ -60,38 +145,38 @@ const BasicLayout = props => { ...@@ -60,38 +145,38 @@ const BasicLayout = props => {
onMenuHeaderClick={() => {}} onMenuHeaderClick={() => {}}
footerRender={() => defaultFooterDom} footerRender={() => defaultFooterDom}
rightContentRender={() => <RightContent />} rightContentRender={() => <RightContent />}
route={{ route={
routes: config.routes, {
}} // routes: config.routes,
}
}
location={{ location={{
pathname, pathname,
}} }}
menuDataRender={() => [ menuDataRender={menuDataProps => {
{ console.log(menuDataProps);
path: '/', menuDataProps.forEach(item => {
component: 'BasicLayout', if (item.name == '机构列表') {
name: 'Dashboard', console.log('机构列表');
icon: 'icon-dashboard', axios.get(`${basicUrl}U_GetOUTree?_version=9999`).then(result => {
routes: [ console.log(result.data);
{ item.routes = [
path: '/Welcome/1', {
name: '一级页面', path: '/ou/orgList',
}, name: '机构列表11',
{ },
path: '/Welcome/2', ];
name: '二级页面', });
}, }
{ });
path: '/Welcome/3',
name: '三级页面', return menuData;
}, }}
],
},
]}
menuItemRender={(menuItemProps, defaultDom) => { menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || !menuItemProps.path) { if (menuItemProps.isUrl || !menuItemProps.path) {
return defaultDom; return defaultDom;
} }
// console.log(menuItemProps);
return <Link to={menuItemProps.path}>{defaultDom}</Link>; return <Link to={menuItemProps.path}>{defaultDom}</Link>;
}} }}
itemRender={(route, params, routes, paths) => { itemRender={(route, params, routes, paths) => {
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import axios from 'axios';
import { import { Alert, Checkbox } from 'antd';
Alert,
Checkbox,
} from 'antd';
import LoginForm from './components/Login'; import LoginForm from './components/Login';
import styles from './style.less'; import styles from './style.less';
...@@ -20,6 +18,7 @@ const LoginMessage = ({ content }) => ( ...@@ -20,6 +18,7 @@ const LoginMessage = ({ content }) => (
showIcon showIcon
/> />
); );
const basicUrl = 'http://localhost:8080/Cityinterface/rest/services/OMS.svc/';
const Login = props => { const Login = props => {
const { userLogin = {}, submitting } = props; const { userLogin = {}, submitting } = props;
...@@ -28,8 +27,28 @@ const Login = props => { ...@@ -28,8 +27,28 @@ const Login = props => {
const [type, setType] = useState('account'); const [type, setType] = useState('account');
const handleSubmit = values => { const handleSubmit = values => {
/* eslint-disable no-console */ /* eslint-disable no-console */
console.log(values); console.log(values); // eg:{userName: "123", password: "123"}
window.location.href = '/'; axios
.get(
`${basicUrl}L_GetCheckUser?loginName=${values.userName}&password=${
values.password
}`,
)
.then(result => {
console.log(result.data);
if (result.data.success == true && result.data.pass == true) {
const { userMode } = result.data;
localStorage.setItem('userMode', userMode);
if (userMode == 'admin' || userMode == 'super') {
window.location.href = '/dbm/dbInit/';
}
if (userMode == 'common') {
window.location.href = '/ou/orgList/';
}
} else {
alert('错误,没有权限');
}
});
}; };
return ( return (
......
...@@ -20,18 +20,44 @@ export default { ...@@ -20,18 +20,44 @@ export default {
component: BasicLayout, component: BasicLayout,
routes: [ routes: [
{ {
path: '/Welcome/1', path: '/dbm/dbInit',
name: '一级页面', name: '数据库初始化',
component: Welcome, component: Welcome,
}, },
{ {
path: '/Welcome/2', path: '/dbm/dbsm',
name: '二级页面', name: '数据库标准化管理',
component: Welcome, component: Welcome,
}, },
{ {
path: '/Welcome/3', path: '/ou/orgList',
name: '三级页面', name: '机构列表',
component: Welcome,
},
{
path: '/basicConfig',
name: '基础通用配置',
component: Welcome,
},
{
path: '/web5',
name: 'Web5配置',
component: Welcome,
},
{
path: '/app',
name: '手持系统配置',
component: Welcome,
},
{
path: '/miniPro',
name: '小程序配置',
authority: ['admin', 'user'],
component: Welcome,
},
{
path: '/log',
name: '日志管理',
component: Welcome, component: Welcome,
}, },
], ],
......
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