Skip to content

Commit

Permalink
Step 12.处理用户创建
Browse files Browse the repository at this point in the history
  • Loading branch information
JobbyM committed Apr 27, 2017
1 parent 358caf1 commit d917327
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/Users/Users.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
.normal {
}

.create {
margin-bottom: 1.5em;
}

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

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

const columns = [
{
title: 'Name',
Expand Down Expand Up @@ -64,6 +71,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
return (
<div className={styles.normal}>
<div>
<div className={styles.create}>
<UserModal record={{}} onOk={createHandler}>
<Button type="primary">Create User</Button>
</UserModal>
</div>
<Table
columns={columns}
dataSource={dataSource}
Expand Down
5 changes: 5 additions & 0 deletions src/models/users.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/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ export function patch(id, values) {
body: JSON.stringify(values),
});
}

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

0 comments on commit d917327

Please sign in to comment.