|
| 1 | +/* |
| 2 | + * |
| 3 | + * ThreadsTable |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +import React from 'react' |
| 8 | +import PropTypes from 'prop-types' |
| 9 | +import { Table, Button } from 'antd' |
| 10 | + |
| 11 | +import Pagi from '../Pagi' |
| 12 | +import { TableLoading } from '../LoadingEffects' |
| 13 | +import { Space } from '../BaseStyled' |
| 14 | + |
| 15 | +import { OperationWrapper } from './styles' |
| 16 | + |
| 17 | +import { makeDebugger, Trans } from '../../utils' |
| 18 | + |
| 19 | +/* eslint-disable no-unused-vars */ |
| 20 | +const debug = makeDebugger('c:ThreadsTable:index') |
| 21 | +/* eslint-enable no-unused-vars */ |
| 22 | + |
| 23 | +class ThreadsTable extends React.PureComponent { |
| 24 | + columns() { |
| 25 | + const { |
| 26 | + /* |
| 27 | + setCommunity, |
| 28 | + unsetCommunity, |
| 29 | + unsetTag, |
| 30 | + setTag, |
| 31 | + */ |
| 32 | + onEdit, |
| 33 | + onDelete, |
| 34 | + } = this.props |
| 35 | + |
| 36 | + return [ |
| 37 | + { |
| 38 | + title: 'id', |
| 39 | + dataIndex: 'id', |
| 40 | + align: 'center', |
| 41 | + width: 80, |
| 42 | + }, |
| 43 | + { |
| 44 | + title: '标题', |
| 45 | + width: 300, |
| 46 | + dataIndex: 'title', |
| 47 | + align: 'center', |
| 48 | + render: text => ( |
| 49 | + <div> |
| 50 | + {Trans(text)}({text}) |
| 51 | + </div> |
| 52 | + ), |
| 53 | + }, |
| 54 | + { |
| 55 | + title: 'raw', |
| 56 | + width: 200, |
| 57 | + dataIndex: 'raw', |
| 58 | + align: 'center', |
| 59 | + }, |
| 60 | + { |
| 61 | + title: '操作', |
| 62 | + width: 200, |
| 63 | + dataIndex: '', |
| 64 | + align: 'center', |
| 65 | + render: (text, record) => ( |
| 66 | + <OperationWrapper> |
| 67 | + <Button |
| 68 | + size="small" |
| 69 | + type="primary" |
| 70 | + ghost |
| 71 | + onClick={onEdit.bind(this, record)} |
| 72 | + > |
| 73 | + 编辑 |
| 74 | + </Button> |
| 75 | + <Space right="10px" /> |
| 76 | + <Button |
| 77 | + size="small" |
| 78 | + type="red" |
| 79 | + ghost |
| 80 | + onClick={onDelete.bind(this, record)} |
| 81 | + > |
| 82 | + 删除 |
| 83 | + </Button> |
| 84 | + </OperationWrapper> |
| 85 | + ), |
| 86 | + }, |
| 87 | + ] |
| 88 | + } |
| 89 | + |
| 90 | + render() { |
| 91 | + const { data, loading, pageChange } = this.props |
| 92 | + |
| 93 | + return ( |
| 94 | + <React.Fragment> |
| 95 | + {data ? ( |
| 96 | + <div> |
| 97 | + <Table |
| 98 | + columns={this.columns()} |
| 99 | + dataSource={data.entries} |
| 100 | + scroll={{ x: 2000 }} |
| 101 | + loading={TableLoading(loading)} |
| 102 | + pagination={false} |
| 103 | + /> |
| 104 | + <Pagi |
| 105 | + left="-10px" |
| 106 | + pageNumber={data.pageNumber} |
| 107 | + pageSize={data.pageSize} |
| 108 | + totalCount={data.totalCount} |
| 109 | + onChange={pageChange} |
| 110 | + /> |
| 111 | + </div> |
| 112 | + ) : null} |
| 113 | + </React.Fragment> |
| 114 | + ) |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +ThreadsTable.propTypes = { |
| 119 | + data: PropTypes.any.isRequired, |
| 120 | + loading: PropTypes.bool, |
| 121 | + pageChange: PropTypes.func, |
| 122 | + /* |
| 123 | + setCommunity: PropTypes.func, |
| 124 | + unsetCommunity: PropTypes.func, |
| 125 | + unsetTag: PropTypes.func, |
| 126 | + setTag: PropTypes.func, |
| 127 | + */ |
| 128 | + onEdit: PropTypes.func, |
| 129 | + onDelete: PropTypes.func, |
| 130 | +} |
| 131 | + |
| 132 | +ThreadsTable.defaultProps = { |
| 133 | + loading: false, |
| 134 | + pageChange: debug, |
| 135 | + /* |
| 136 | + setCommunity: debug, |
| 137 | + unsetCommunity: debug, |
| 138 | + unsetTag: debug, |
| 139 | + setTag: debug, |
| 140 | + */ |
| 141 | + onEdit: debug, |
| 142 | + onDelete: debug, |
| 143 | +} |
| 144 | + |
| 145 | +export default ThreadsTable |
0 commit comments