Commit 7edd22db authored by 张烨's avatar 张烨

feat: login and logout

parent 051fd8c0
...@@ -99,6 +99,7 @@ module.exports = { ...@@ -99,6 +99,7 @@ module.exports = {
'no-param-reassign': 0, 'no-param-reassign': 0,
'prefer-const': 0, 'prefer-const': 0,
'button-has-type': 0, 'button-has-type': 0,
'symbol-description':0,
}, },
settings: { settings: {
'import/resolver': { 'import/resolver': {
......
...@@ -5,12 +5,24 @@ import { ...@@ -5,12 +5,24 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import { Avatar, Menu, Spin } from 'antd'; import { Avatar, Menu, Spin } from 'antd';
import React from 'react'; import React from 'react';
import { withRouter } from 'react-router-dom';
import HeaderDropdown from '../HeaderDropdown'; import HeaderDropdown from '../HeaderDropdown';
import styles from './index.less'; import styles from './index.less';
import { setAuthority } from '@/utils/authority';
class AvatarDropdown extends React.Component { class AvatarDropdown extends React.Component {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
onMenuClick = event => {}; onMenuClick = event => {
const { history } = this.props;
switch (event.key) {
case 'logout':
setAuthority([]);
history.push('/user/login');
break;
default:
break;
}
};
render() { render() {
const { const {
...@@ -26,7 +38,7 @@ class AvatarDropdown extends React.Component { ...@@ -26,7 +38,7 @@ class AvatarDropdown extends React.Component {
selectedKeys={[]} selectedKeys={[]}
onClick={this.onMenuClick} onClick={this.onMenuClick}
> >
{ {/* {
<Menu.Item key="center"> <Menu.Item key="center">
<UserOutlined /> <UserOutlined />
个人中心 个人中心
...@@ -38,7 +50,7 @@ class AvatarDropdown extends React.Component { ...@@ -38,7 +50,7 @@ class AvatarDropdown extends React.Component {
个人设置 个人设置
</Menu.Item> </Menu.Item>
} }
{<Menu.Divider />} {<Menu.Divider />} */}
<Menu.Item key="logout"> <Menu.Item key="logout">
<LogoutOutlined /> <LogoutOutlined />
...@@ -72,4 +84,4 @@ class AvatarDropdown extends React.Component { ...@@ -72,4 +84,4 @@ class AvatarDropdown extends React.Component {
} }
} }
export default AvatarDropdown; export default withRouter(AvatarDropdown);
...@@ -6,7 +6,7 @@ import config from '../../routes/config'; ...@@ -6,7 +6,7 @@ import config from '../../routes/config';
import Authozed from '@/utils/authority'; import Authozed from '@/utils/authority';
import UserLogin from '@/pages/user/login'; import UserLogin from '@/pages/user/login';
import UserLayout from '@/layouts/UserLayout'; import UserLayout from '@/layouts/UserLayout';
import { AUTHORITY, BASENAME } from '@/utils/constants';
export default function App() { export default function App() {
return ( return (
<> <>
...@@ -19,9 +19,9 @@ export default function App() { ...@@ -19,9 +19,9 @@ export default function App() {
<UserLogin /> <UserLogin />
</UserLayout> </UserLayout>
} }
authority="login" authority={[AUTHORITY.LOGIN]}
> >
<Router basename={process.env.PUBLIC_PATH || 'reactOMS'}> <Router basename={BASENAME}>
<Switch>{renderRoutes(config.routes)}</Switch> <Switch>{renderRoutes(config.routes)}</Switch>
</Router> </Router>
</Authozed> </Authozed>
......
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 { AUTHORITY, BASENAME, 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'; import { setAuthority } from '@/utils/authority';
...@@ -33,12 +33,12 @@ const Login = props => { ...@@ -33,12 +33,12 @@ 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]); setAuthority([AUTHORITY.LOGIN, AUTHORITY[userMode]]);
window.location.href = '/dbm/dbInit/'; window.location.href = `/${BASENAME}/dbm/dbInit/`;
} }
if (userMode === USER_MODE.COMMON) { if (userMode === USER_MODE.COMMON) {
setAuthority(['login', USER_MODE.COMMON]); setAuthority([AUTHORITY.LOGIN, AUTHORITY.COMMON]);
window.location.href = '/ou/orgList/'; window.location.href = `/${BASENAME}/ou/orgList/`;
} }
} else { } else {
alert('错误,没有权限'); alert('错误,没有权限');
......
...@@ -2,6 +2,12 @@ export const RESTART_ON_REMOUNT = '@@saga-injector/restart-on-remount'; ...@@ -2,6 +2,12 @@ export const RESTART_ON_REMOUNT = '@@saga-injector/restart-on-remount';
export const DAEMON = '@@saga-injector/daemon'; export const DAEMON = '@@saga-injector/daemon';
export const ONCE_TILL_UNMOUNT = '@@saga-injector/once-till-unmount'; export const ONCE_TILL_UNMOUNT = '@@saga-injector/once-till-unmount';
export const BASENAME = process.env.PUBLIC_PATH || 'reactOMS';
export const AUTHORITY = {
LOGIN: 'LOGIN',
admin: 'admin',
super: 'super',
};
export const USER_MODE = { export const USER_MODE = {
ADMIN: 'admin', ADMIN: 'admin',
SUPER: 'super', SUPER: 'super',
......
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