Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit 9422664

Browse files
committed
Update login system
1 parent 2c99aae commit 9422664

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

src/Page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const Page = ({ app }: any) => (
1515
<HashRouter>
1616
<Switch>
1717
<Route exact path="/" render={() => <Redirect to="/app/dashboard" push />} />
18+
<Route exact path="/app" render={() => <Redirect to="/app/dashboard" push />} />
1819
<Route path="/login" component={Login} />
1920
<Route path="/app" render={(props: any) => <App app={app} {...props} />} />
2021
<Route path="/exception/403" component={NoPermission} />

src/components/Content/Content.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ interface InternalProps {
66
}
77

88
export default function Content(props: InternalProps) {
9-
const styles = {
10-
padding: '0 40px',
11-
};
12-
139
return (
14-
<Layout.Content style={styles} >
15-
{props.children}
16-
</Layout.Content>
10+
<Layout.Content>{props.children}</Layout.Content>
1711
);
1812
}

src/components/Header/Header.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
import { Avatar, Badge, Dropdown, Icon, Layout, Menu } from 'antd';
22
import { connect } from 'dva';
33
import Debounce from 'lodash-decorators/debounce';
4-
import React, { Component } from 'react';
4+
import React, { PureComponent } from 'react';
55

66
import { UserInfo } from '../../models/global';
77
import styles from './Header.module.scss';
88
import NoticePane from './NoticePane';
99

1010
const { ItemGroup } = Menu;
1111

12-
interface InternalProps {
12+
interface DvaProps {
13+
logout: () => void;
14+
loadMoreNotices: (params?: any) => void;
15+
}
16+
17+
interface InternalProps extends DvaProps {
1318
notices: any[];
1419
userInfo: UserInfo;
1520
collapsed: boolean;
1621
hasMore: boolean;
1722
fetchingNotices: boolean;
18-
loadMoreNotices: (params?: any) => void;
1923
onCollapse: (collapsed: boolean) => void;
2024
}
2125

2226
interface InternalState {
2327
showNoticePane: boolean;
2428
}
2529

26-
export class Header extends Component<InternalProps, InternalState> {
30+
export class Header extends PureComponent<InternalProps, InternalState> {
2731
private isFullScreen = false;
2832

2933
private constructor(props: InternalProps) {
@@ -57,7 +61,7 @@ export class Header extends Component<InternalProps, InternalState> {
5761
}
5862

5963
public signOut() {
60-
// TODO: Need to finish sign out logic
64+
this.props.logout();
6165
}
6266

6367
public onVisibleChange(visible: boolean) {
@@ -139,6 +143,9 @@ const mapDispatchToProps = (dispatch: any) => {
139143
payload: collapsed,
140144
});
141145
},
146+
logout: () => {
147+
dispatch({type: 'global/logout'});
148+
},
142149
loadMoreNotices: (params?: any) => {
143150
dispatch({
144151
type: 'global/fetchNotifications',

src/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ import { Global } from './models';
1010
import Page from './Page';
1111
import { errorHandle } from './utils/errorHandle';
1212

13-
const logger = Env === EnvType.Development ? createLogger() : () => null;
13+
// Dva middleware
14+
const middleware = [];
15+
16+
if (Env === EnvType.Development) {
17+
middleware.push(createLogger());
18+
}
1419

1520
const app: any = dva({
1621
onError(error: any) {
1722
// Catch redux action errors
1823
errorHandle(error, app._store.dispatch);
1924
},
2025

21-
onAction: [logger],
26+
onAction: middleware,
2227

2328
// 其他第三方 Reducer 配置
2429
extraReducers: {

src/models/global.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ export default {
5353
*login(action: any, { call, put }: any) {
5454
try {
5555
const { payload } = action;
56-
const res = yield call(GlobalService.auth, payload);
56+
yield call(GlobalService.auth, payload);
5757
yield put({
5858
type: 'authorize',
5959
payload: {
6060
isAuthenticated: true,
6161
permissions: [],
6262
},
6363
});
64+
yield put(routerRedux.push('/app'));
6465
} catch (error) {
6566
throw error;
6667
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.dashboard {
2-
2+
margin: 0 20px;
33
}

0 commit comments

Comments
 (0)