|
| 1 | +/* |
| 2 | + * |
| 3 | + * UsersTable |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +import React from 'react' |
| 8 | +import PropTypes from 'prop-types' |
| 9 | +import { Table } from 'antd' |
| 10 | + |
| 11 | +import Pagi from '../Pagi' |
| 12 | +import { TableLoading } from '../LoadingEffects' |
| 13 | +import MaybeCell from '../MaybeCell' |
| 14 | +import UserCell from '../UserCell' |
| 15 | +import TimeStampCell from '../TimeStampCell' |
| 16 | +import { makeDebugger } from '../../utils' |
| 17 | + |
| 18 | +import PermissionCell from '../PermissionCell' |
| 19 | +import SexCell from '../SexCell' |
| 20 | + |
| 21 | +// import { Wrapper } from './styles' |
| 22 | + |
| 23 | +/* eslint-disable no-unused-vars */ |
| 24 | +const debug = makeDebugger('c:UsersTable:index') |
| 25 | +/* eslint-enable no-unused-vars */ |
| 26 | + |
| 27 | +class UsersTable extends React.PureComponent { |
| 28 | + columns() { |
| 29 | + const { cmsPermisstionOnChange } = this.props |
| 30 | + |
| 31 | + return [ |
| 32 | + { |
| 33 | + title: 'id', |
| 34 | + dataIndex: 'id', |
| 35 | + align: 'center', |
| 36 | + fixed: 'left', |
| 37 | + width: 80, |
| 38 | + }, |
| 39 | + { |
| 40 | + title: '头像', |
| 41 | + width: 180, |
| 42 | + dataIndex: '', |
| 43 | + align: 'center', |
| 44 | + fixed: 'left', |
| 45 | + render: record => { |
| 46 | + const user = { nickname: record.nickname, avatar: record.avatar } |
| 47 | + return <UserCell user={user} left="20px" /> |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + title: '关注社区', |
| 52 | + dataIndex: 'subscribedCommunitiesCount', |
| 53 | + align: 'center', |
| 54 | + width: 150, |
| 55 | + }, |
| 56 | + { |
| 57 | + title: 'bio', |
| 58 | + dataIndex: 'bio', |
| 59 | + align: 'center', |
| 60 | + width: 380, |
| 61 | + render: text => { |
| 62 | + return <div style={{ textAlign: 'left' }}>{text}</div> |
| 63 | + }, |
| 64 | + }, |
| 65 | + { |
| 66 | + title: 'sex', |
| 67 | + dataIndex: 'sex', |
| 68 | + align: 'center', |
| 69 | + width: 80, |
| 70 | + render: text => { |
| 71 | + return <SexCell sex={text} /> |
| 72 | + }, |
| 73 | + }, |
| 74 | + { |
| 75 | + title: 'cms权限', |
| 76 | + dataIndex: 'cmsPassportString', |
| 77 | + align: 'center', |
| 78 | + width: 200, |
| 79 | + render: (text, record) => ( |
| 80 | + <PermissionCell source={record} onMutate={cmsPermisstionOnChange} /> |
| 81 | + ), |
| 82 | + }, |
| 83 | + { |
| 84 | + title: 'email', |
| 85 | + dataIndex: 'email', |
| 86 | + align: 'center', |
| 87 | + width: 100, |
| 88 | + render: text => <MaybeCell text={text} />, |
| 89 | + }, |
| 90 | + { |
| 91 | + title: 'qq', |
| 92 | + dataIndex: 'qq', |
| 93 | + align: 'center', |
| 94 | + width: 100, |
| 95 | + render: text => <MaybeCell text={text} />, |
| 96 | + }, |
| 97 | + { |
| 98 | + title: 'weixin', |
| 99 | + dataIndex: 'weixin', |
| 100 | + align: 'center', |
| 101 | + width: 150, |
| 102 | + render: text => <MaybeCell text={text} />, |
| 103 | + }, |
| 104 | + { |
| 105 | + title: 'weibo', |
| 106 | + dataIndex: 'weibo', |
| 107 | + align: 'center', |
| 108 | + width: 100, |
| 109 | + render: text => <MaybeCell text={text} />, |
| 110 | + }, |
| 111 | + { |
| 112 | + title: '位置', |
| 113 | + dataIndex: 'location', |
| 114 | + align: 'center', |
| 115 | + width: 220, |
| 116 | + render: text => <MaybeCell text={text} />, |
| 117 | + }, |
| 118 | + { |
| 119 | + title: '时间戳', |
| 120 | + width: 120, |
| 121 | + align: 'center', |
| 122 | + render: (text, record) => <TimeStampCell data={record} />, |
| 123 | + }, |
| 124 | + ] |
| 125 | + } |
| 126 | + |
| 127 | + render() { |
| 128 | + const { data, loading, pageChange } = this.props |
| 129 | + |
| 130 | + return ( |
| 131 | + <React.Fragment> |
| 132 | + {data ? ( |
| 133 | + <React.Fragment> |
| 134 | + <Table |
| 135 | + columns={this.columns()} |
| 136 | + dataSource={data.entries} |
| 137 | + scroll={{ x: 2200 }} |
| 138 | + loading={TableLoading(loading)} |
| 139 | + pagination={false} |
| 140 | + /> |
| 141 | + <Pagi |
| 142 | + left="-10px" |
| 143 | + pageNumber={data.pageNumber} |
| 144 | + pageSize={data.pageSize} |
| 145 | + totalCount={data.totalCount} |
| 146 | + onChange={pageChange} |
| 147 | + /> |
| 148 | + </React.Fragment> |
| 149 | + ) : null} |
| 150 | + </React.Fragment> |
| 151 | + ) |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +UsersTable.propTypes = { |
| 156 | + data: PropTypes.any.isRequired, |
| 157 | + loading: PropTypes.bool, |
| 158 | + pageChange: PropTypes.func, |
| 159 | + cmsPermisstionOnChange: PropTypes.func, |
| 160 | +} |
| 161 | + |
| 162 | +UsersTable.defaultProps = { |
| 163 | + loading: false, |
| 164 | + pageChange: debug, |
| 165 | + cmsPermisstionOnChange: debug, |
| 166 | +} |
| 167 | + |
| 168 | +export default UsersTable |
0 commit comments