From d917327aee21e177e37d44d9dd73c685f0e52bb2 Mon Sep 17 00:00:00 2001 From: JobbyM Date: Thu, 27 Apr 2017 09:52:25 +0800 Subject: [PATCH] =?UTF-8?q?Step=2012.=E5=A4=84=E7=90=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Users/Users.css | 4 ++++ src/components/Users/Users.js | 14 +++++++++++++- src/models/users.js | 5 +++++ src/services/users.js | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/components/Users/Users.css b/src/components/Users/Users.css index e75e7e0..b4933a0 100644 --- a/src/components/Users/Users.css +++ b/src/components/Users/Users.css @@ -2,6 +2,10 @@ .normal { } +.create { + margin-bottom: 1.5em; +} + .operation a { margin: 0 .5em; } diff --git a/src/components/Users/Users.js b/src/components/Users/Users.js index 1f78681..c263cab 100644 --- a/src/components/Users/Users.js +++ b/src/components/Users/Users.js @@ -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'; @@ -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', @@ -64,6 +71,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) { return (
+
+ + + +
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 }) { diff --git a/src/services/users.js b/src/services/users.js index aa8b25a..b18d65a 100644 --- a/src/services/users.js +++ b/src/services/users.js @@ -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), + }); +}