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

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

parent e59c081d
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import {
matchRoutes,
renderRoutes,
} from 'react-router-config';
import { matchRoutes, renderRoutes } from 'react-router-config';
import { Link } from 'react-router-dom';
import { GithubOutlined } from '@ant-design/icons';
......@@ -11,7 +9,7 @@ import ProLayout, { DefaultFooter } from '@ant-design/pro-layout';
import logo from '../assets/logo.svg';
import RightContent from '../components/GlobalHeader/RightContent';
import config from '../routes/config';
// import config from '../routes/config';
// const noMatch = (
// <Result
......@@ -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 => {
/* eslint-disable no-unused-vars */
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
matchRoutes(props.route.routes, props.location.pathname);
......@@ -60,38 +145,38 @@ const BasicLayout = props => {
onMenuHeaderClick={() => {}}
footerRender={() => defaultFooterDom}
rightContentRender={() => <RightContent />}
route={{
routes: config.routes,
}}
route={
{
// routes: config.routes,
}
}
location={{
pathname,
}}
menuDataRender={() => [
{
path: '/',
component: 'BasicLayout',
name: 'Dashboard',
icon: 'icon-dashboard',
routes: [
{
path: '/Welcome/1',
name: '一级页面',
},
{
path: '/Welcome/2',
name: '二级页面',
},
{
path: '/Welcome/3',
name: '三级页面',
},
],
},
]}
menuDataRender={menuDataProps => {
console.log(menuDataProps);
menuDataProps.forEach(item => {
if (item.name == '机构列表') {
console.log('机构列表');
axios.get(`${basicUrl}U_GetOUTree?_version=9999`).then(result => {
console.log(result.data);
item.routes = [
{
path: '/ou/orgList',
name: '机构列表11',
},
];
});
}
});
return menuData;
}}
menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || !menuItemProps.path) {
return defaultDom;
}
// console.log(menuItemProps);
return <Link to={menuItemProps.path}>{defaultDom}</Link>;
}}
itemRender={(route, params, routes, paths) => {
......
import React, { useState } from 'react';
import axios from 'axios';
import {
Alert,
Checkbox,
} from 'antd';
import { Alert, Checkbox } from 'antd';
import LoginForm from './components/Login';
import styles from './style.less';
......@@ -20,6 +18,7 @@ const LoginMessage = ({ content }) => (
showIcon
/>
);
const basicUrl = 'http://localhost:8080/Cityinterface/rest/services/OMS.svc/';
const Login = props => {
const { userLogin = {}, submitting } = props;
......@@ -28,8 +27,28 @@ const Login = props => {
const [type, setType] = useState('account');
const handleSubmit = values => {
/* eslint-disable no-console */
console.log(values);
window.location.href = '/';
console.log(values); // eg:{userName: "123", password: "123"}
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 (
......
......@@ -20,18 +20,44 @@ export default {
component: BasicLayout,
routes: [
{
path: '/Welcome/1',
name: '一级页面',
path: '/dbm/dbInit',
name: '数据库初始化',
component: Welcome,
},
{
path: '/Welcome/2',
name: '二级页面',
path: '/dbm/dbsm',
name: '数据库标准化管理',
component: Welcome,
},
{
path: '/Welcome/3',
name: '三级页面',
path: '/ou/orgList',
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,
},
],
......
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