Skip to content

Commit

Permalink
feat: step 11 处理用户创建
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivocin committed Sep 8, 2018
1 parent 1355b7d commit 6871e25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/pages/users/components/Users.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.operation a {
margin: 0 .5em;
}

.create {
margin: 1.5em 0;
}
14 changes: 13 additions & 1 deletion src/pages/users/components/Users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'dva';
import { Table, Pagination, Popconfirm } from 'antd';
import { Table, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import { PAGE_SIZE } from '../constants';
import { routerRedux } from 'dva/router';
Expand All @@ -20,6 +20,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
});
}

function createHandler(values) {
dispatch({
type: 'users/create',
payload: values,
});
}

function pageChangeHandler(page) {
dispatch(routerRedux.push({
pathname: '/users',
Expand Down Expand Up @@ -63,6 +70,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
return (
<div>
<div>
<div className={styles.create}>
<UserModal record={{}} onOk={createHandler}>
<Button type="primary">Create User</Button>
</UserModal>
</div>
<Table
loading={loading}
columns={columns}
Expand Down
5 changes: 5 additions & 0 deletions src/pages/users/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default {
const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } });
},
*create({ payload: values }, { call, put, select }) {
yield call(usersService.create, values);
const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } });
},
},
subscriptions: {
setup({ dispatch, history }) {
Expand Down
7 changes: 7 additions & 0 deletions src/pages/users/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ export function patch(id, values) {
method: 'PATCH',
body: JSON.stringify(values),
});
}

export function create(values) {
return request('/api/users', {
method: 'POST',
body: JSON.stringify(values),
});
}

0 comments on commit 6871e25

Please sign in to comment.