From 547811ced9f22eb129cf4dc59ef88b3496bcd77f Mon Sep 17 00:00:00 2001 From: pmg1989 <972401854@qq.com> Date: Sat, 25 Feb 2017 21:40:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=8A=A8=E7=94=BB=E6=8F=90?= =?UTF-8?q?=E5=8F=96TableBodyWrapper.js=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/TableBodyWrapper.js | 67 +++++ src/components/common/TableBodyWrapper.less | 0 src/components/users/list.js | 265 +++++++++----------- src/routes/users.js | 1 + 4 files changed, 185 insertions(+), 148 deletions(-) create mode 100644 src/components/common/TableBodyWrapper.js create mode 100644 src/components/common/TableBodyWrapper.less diff --git a/src/components/common/TableBodyWrapper.js b/src/components/common/TableBodyWrapper.js new file mode 100644 index 0000000..658b400 --- /dev/null +++ b/src/components/common/TableBodyWrapper.js @@ -0,0 +1,67 @@ +import React, { PropTypes } from 'react' +import { TweenOneGroup } from 'rc-tween-one' +import styles from './TableBodyWrapper.less' + +const enterAnim = [ + { + opacity: 0, + x: 30, + backgroundColor: '#fffeee', + duration: 0 + }, { + height: 0, + duration: 200, + type: 'from', + delay: 250, + ease: 'easeOutQuad', + onComplete: (e) => { + e.target.style.height = 'auto' + }, + }, { + opacity: 1, + x: 0, + duration: 250, + ease: 'easeOutQuad' + }, { + delay: 1000, + backgroundColor: '#fff' + } +] + +const leaveAnim = [ + { + duration: 250, + x: -30, + opacity: 0 + }, { + height: 0, + duration: 200, + ease: 'easeOutQuad' + } +] + +const TableBodyWrapper = ({ body, page = 1, current }) => { + + // 切换分页去除动画; + if(current != +page) { + return body + } + + return ( + + {body.props.children} + + ) +} + +TableBodyWrapper.propTypes = { + page: PropTypes.any, + current: PropTypes.number.isRequired +} + +export default TableBodyWrapper diff --git a/src/components/common/TableBodyWrapper.less b/src/components/common/TableBodyWrapper.less new file mode 100644 index 0000000..e69de29 diff --git a/src/components/users/list.js b/src/components/users/list.js index 6120340..4b78130 100644 --- a/src/components/users/list.js +++ b/src/components/users/list.js @@ -1,162 +1,131 @@ -import React from 'react' +import React, {PropTypes} from 'react' import {Table, Dropdown, Button, Menu, Icon, Modal} from 'antd' -import {TweenOneGroup} from 'rc-tween-one' import styles from './list.less' +import TableBodyWrapper from '../common/TableBodyWrapper' + const confirm = Modal.confirm +function list({ + loading, + dataSource, + pagination, + updatePower, + deletePower, + onPageChange, + onDeleteItem, + onEditItem, + onStatusItem, + location +}) { -class list extends React.Component { - constructor (props) { - super(props) - this.enterAnim = [ - { - opacity: 0, - x: 30, - backgroundColor: '#fffeee', - duration: 0 - }, { - height: 0, - duration: 200, - type: 'from', - delay: 250, - ease: 'easeOutQuad', - onComplete: this.onEnd - }, { - opacity: 1, - x: 0, - duration: 250, - ease: 'easeOutQuad' - }, { - delay: 1000, - backgroundColor: '#fff' - } - ] - this.leaveAnim = [ - { - duration: 250, - opacity: 0 - }, { - height: 0, - duration: 200, - ease: 'easeOutQuad' - } - ] - const {current} = this.props.pagination - this.currentPage = current - this.newPage = current - } - - getBodyWrapper = (body) => { - // 切换分页去除动画; - if (this.currentPage !== this.newPage) { - this.currentPage = this.newPage - return body + const handleMenuClick = (record, e) => { + if (e.key === '1') { + onEditItem(record) + } else if (e.key === '2') { + confirm({ + title: '您确定要删除这条记录吗?', + onOk () { + onDeleteItem(record.id) + } + }) } - return ( - - {body.props.children} - - ) } - handleMenuClick = (record, e) => { - const {onDeleteItem, onEditItem} = this.props - if (e.key === '1') { - onEditItem(record) - } else if (e.key === '2') { - confirm({ - title: '您确定要删除这条记录吗?', - onOk () { - onDeleteItem(record.id) - } - }) + const columns = [ + { + title: '头像', + dataIndex: 'avatar', + key: 'avatar', + width: 64, + className: styles.avatar, + render: (text) => + }, { + title: '姓名', + dataIndex: 'name', + key: 'name' + }, { + title: '昵称', + dataIndex: 'nickName', + key: 'nickName' + }, { + title: '年龄', + dataIndex: 'age', + key: 'age', + render: (text) => {text}岁 + }, { + title: '性别', + dataIndex: 'isMale', + key: 'isMale', + render: (text) => {text + ? '男' + : '女'} + }, { + title: '电话', + dataIndex: 'phone', + key: 'phone' + }, { + title: '邮箱', + dataIndex: 'email', + key: 'email' + }, { + title: '住址', + dataIndex: 'address', + key: 'address' + }, { + title: '创建时间', + dataIndex: 'createTime', + key: 'createTime' + }, { + title: '操作', + key: 'operation', + width: 100, + render: (text, record) => { + return ( handleMenuClick(record, e)}> + 编辑 + 删除 + }> + + ) + } + } + ] + + const getBodyWrapperProps = { + page: location.query.page, + current: pagination.current } + + const getBodyWrapper = (body) => () + + return ( +
+ record.id} + getBodyWrapper={getBodyWrapper} + /> + + ) } - onEnd = (e) => { - e.target.style.height = 'auto' - } - - async pageChange (pagination) { - await this.props.onPageChange(pagination) - this.newPage = pagination.current - } - - render () { - const { - loading, - dataSource, - pagination, - onDeleteItem, - onEditItem - } = this.props - const columns = [ - { - title: '头像', - dataIndex: 'avatar', - key: 'avatar', - width: 64, - className: styles.avatar, - render: (text) => - }, { - title: '姓名', - dataIndex: 'name', - key: 'name' - }, { - title: '昵称', - dataIndex: 'nickName', - key: 'nickName' - }, { - title: '年龄', - dataIndex: 'age', - key: 'age', - render: (text) => {text}岁 - }, { - title: '性别', - dataIndex: 'isMale', - key: 'isMale', - render: (text) => {text - ? '男' - : '女'} - }, { - title: '电话', - dataIndex: 'phone', - key: 'phone' - }, { - title: '邮箱', - dataIndex: 'email', - key: 'email' - }, { - title: '住址', - dataIndex: 'address', - key: 'address' - }, { - title: '创建时间', - dataIndex: 'createTime', - key: 'createTime' - }, { - title: '操作', - key: 'operation', - width: 100, - render: (text, record) => { - return ( - 编辑 - 删除 - }> - - ) - } - } - ] - return
-
record.id} getBodyWrapper={this.getBodyWrapper} /> - - } +list.propTypes = { + onPageChange: PropTypes.func, + onDeleteItem: PropTypes.func, + onEditItem: PropTypes.func, + dataSource: PropTypes.array, + loading: PropTypes.any, + pagination: PropTypes.any } export default list diff --git a/src/routes/users.js b/src/routes/users.js index 2832ddf..dd02126 100644 --- a/src/routes/users.js +++ b/src/routes/users.js @@ -30,6 +30,7 @@ function Users ({ location, dispatch, users }) { dataSource: list, loading, pagination: pagination, + location, onPageChange (page) { const { query, pathname } = location dispatch(routerRedux.push({