Skip to content

Commit c9ef536

Browse files
committed
Notification
1 parent cba4ee8 commit c9ef536

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/layouts/BasicLayout.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { connect } from 'dva';
33
import { Switch, NavLink, routerRedux } from 'dva/router';
44
import $$ from 'cmn-utils';
5+
import { Notification } from 'components';
56
import './styles/basic.less';
67

78
@connect()
@@ -26,6 +27,7 @@ export default class BasicLayout extends React.PureComponent {
2627
<Switch>
2728
{childRoutes}
2829
</Switch>
30+
<Notification />
2931
</div>
3032
);
3133
}

src/routes/Home/components/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ import { connect } from 'dva';
33
import logo from 'assets/images/logo.png';
44
import './style.less';
55
import BaseComponent from 'components/BaseComponent';
6+
import { Notification } from 'components';
67
import $$ from 'cmn-utils';
8+
const notice = Notification.notice;
79

810
@connect()
911
export default class Home extends BaseComponent {
12+
notice = (e) => {
13+
this.close = notice(e.target.innerHTML, e.target.innerHTML);
14+
}
15+
16+
closeNotice = () => {
17+
this.close && this.close();
18+
}
1019

1120
render() {
1221
const user = $$.getStore('user');
@@ -15,6 +24,13 @@ export default class Home extends BaseComponent {
1524
<div className="home-page">
1625
<img src={logo} alt="" />
1726
<div>Welcome Home {user.name}</div>
27+
<hr />
28+
<button onClick={this.notice}>success</button>
29+
<button onClick={this.notice}>error</button>
30+
<button onClick={this.notice}>warn</button>
31+
<button onClick={this.notice}>default</button>
32+
<button onClick={this.notice}>dark</button> &nbsp;
33+
<button onClick={this.closeNotice}>close</button>
1834
</div>
1935
)
2036
}

src/routes/UserInfo/components/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export default class UserInfo extends Component {
4646
});
4747
}
4848

49+
throwRequestError = () => {
50+
this.props.dispatch({
51+
type: 'userInfo/@request',
52+
payload: {
53+
valueField: 'httpbin',
54+
url: 'http://httpbin.org/post',
55+
method: 'GET',
56+
}
57+
});
58+
}
59+
4960
render() {
5061
const {info, httpbin, pageData} = this.props.userInfo;
5162
const {pageNum, total, totalPages} = pageData;
@@ -90,6 +101,10 @@ export default class UserInfo extends Component {
90101
<button disabled={pageNum < totalPages ? false : true} onClick={e => this.turnPage()}>下一页</button>
91102
当前为第<b>{pageNum}</b>页,总计<b>{total}</b>条数据,共<b>{totalPages}</b>
92103
</div>
104+
105+
<h2>全局异常捕获</h2>
106+
<button onClick={this.throwRequestError}>点我生成一个异常</button>
107+
93108
<PageLoading loading={this.props.loading} />
94109
</div>
95110
)

0 commit comments

Comments
 (0)