Commit 051fd8c0 authored by 张烨's avatar 张烨

feat: add login authority

parent ac33f5ff
{
"compilerOptions": {
"jsx": "react",
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
"exclude": [
"node_modules"
]
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ import check from './CheckPermissions'; ...@@ -4,7 +4,7 @@ import check from './CheckPermissions';
const Authorized = ({ const Authorized = ({
children, children,
authority, authority, // 当前组件渲染需要的权限
noMatch = ( noMatch = (
<Result <Result
status="403" status="403"
......
...@@ -3,6 +3,9 @@ import { Helmet } from 'react-helmet'; ...@@ -3,6 +3,9 @@ import { Helmet } from 'react-helmet';
import { renderRoutes } from 'react-router-config'; import { renderRoutes } from 'react-router-config';
import { BrowserRouter as Router, Switch } from 'react-router-dom'; import { BrowserRouter as Router, Switch } from 'react-router-dom';
import config from '../../routes/config'; import config from '../../routes/config';
import Authozed from '@/utils/authority';
import UserLogin from '@/pages/user/login';
import UserLayout from '@/layouts/UserLayout';
export default function App() { export default function App() {
return ( return (
...@@ -10,9 +13,18 @@ export default function App() { ...@@ -10,9 +13,18 @@ export default function App() {
<Helmet titleTemplate="%s - 运维平台" defaultTitle="运维平台"> <Helmet titleTemplate="%s - 运维平台" defaultTitle="运维平台">
<meta name="description" content="运维平台" /> <meta name="description" content="运维平台" />
</Helmet> </Helmet>
<Authozed
noMatch={
<UserLayout>
<UserLogin />
</UserLayout>
}
authority="login"
>
<Router basename={process.env.PUBLIC_PATH || 'reactOMS'}> <Router basename={process.env.PUBLIC_PATH || 'reactOMS'}>
<Switch>{renderRoutes(config.routes)}</Switch> <Switch>{renderRoutes(config.routes)}</Switch>
</Router> </Router>
</Authozed>
</> </>
); );
} }
...@@ -17,6 +17,7 @@ const UserLayout = props => { ...@@ -17,6 +17,7 @@ const UserLayout = props => {
route = { route = {
routes: [], routes: [],
}, },
children,
} = props; } = props;
// const { formatMessage } = useIntl(); // const { formatMessage } = useIntl();
const { breadcrumb } = getMenuData(route.routes); const { breadcrumb } = getMenuData(route.routes);
...@@ -46,7 +47,7 @@ const UserLayout = props => { ...@@ -46,7 +47,7 @@ const UserLayout = props => {
{/* Ant Design 是西湖区最具影响力的 Web 设计规范 */} {/* Ant Design 是西湖区最具影响力的 Web 设计规范 */}
</div> </div>
</div> </div>
{renderRoutes(route.routes)} {children || renderRoutes(route.routes)}
</div> </div>
<DefaultFooter <DefaultFooter
copyright={`${new Date().getFullYear()} 熊猫智慧水务技术委员会出品`} copyright={`${new Date().getFullYear()} 熊猫智慧水务技术委员会出品`}
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Alert, Checkbox } from 'antd'; import { Alert, Checkbox } from 'antd';
import { login } from '../../../services/user/api'; import { login } from '@/services/user/api';
import { USER_MODE } from '../../../utils/constants'; import { USER_MODE } from '@/utils/constants';
import LoginForm from './components/Login'; import LoginForm from './components/Login';
import styles from './style.less'; import styles from './style.less';
import { setAuthority } from '@/utils/authority';
const { UserName, Password, Submit } = LoginForm; const { UserName, Password, Submit } = LoginForm;
const LoginMessage = ({ content }) => ( const LoginMessage = ({ content }) => (
...@@ -33,9 +33,11 @@ const Login = props => { ...@@ -33,9 +33,11 @@ const Login = props => {
const { userMode } = result; const { userMode } = result;
localStorage.setItem('userMode', userMode); localStorage.setItem('userMode', userMode);
if (userMode === USER_MODE.ADMIN || userMode === USER_MODE.SUPER) { if (userMode === USER_MODE.ADMIN || userMode === USER_MODE.SUPER) {
setAuthority(['login', USER_MODE.ADMIN, USER_MODE.SUPER]);
window.location.href = '/dbm/dbInit/'; window.location.href = '/dbm/dbInit/';
} }
if (userMode === USER_MODE.COMMON) { if (userMode === USER_MODE.COMMON) {
setAuthority(['login', USER_MODE.COMMON]);
window.location.href = '/ou/orgList/'; window.location.href = '/ou/orgList/';
} }
} else { } else {
......
export default (...routerProps) =>
new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 1500);
}).then(() => {});
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