|
| 1 | +import React from 'react' |
| 2 | +import TimeAgo from 'timeago-react' |
| 3 | + |
| 4 | +import { |
| 5 | + Pagi, |
| 6 | + Table, |
| 7 | + TableLoading, |
| 8 | + Button, |
| 9 | + Space, |
| 10 | + UserCell, |
| 11 | + CommunityCell, |
| 12 | + TagsCell, |
| 13 | +} from '../../components' |
| 14 | + |
| 15 | +import { OperationWrapper } from './styles' |
| 16 | +import * as logic from './logic' |
| 17 | + |
| 18 | +/* eslint-disable react/display-name */ |
| 19 | +const columns = [ |
| 20 | + { |
| 21 | + title: 'id', |
| 22 | + dataIndex: 'id', |
| 23 | + align: 'center', |
| 24 | + width: 80, |
| 25 | + fixed: 'left', |
| 26 | + }, |
| 27 | + { |
| 28 | + title: '标题', |
| 29 | + width: 300, |
| 30 | + align: 'left', |
| 31 | + fixed: 'left', |
| 32 | + render: (text, record) => ( |
| 33 | + <div> |
| 34 | + <div>{record.ownerName}</div> |
| 35 | + <div>{record.title}</div> |
| 36 | + </div> |
| 37 | + ), |
| 38 | + }, |
| 39 | + { |
| 40 | + title: '作者', |
| 41 | + width: 200, |
| 42 | + dataIndex: 'author', |
| 43 | + align: 'center', |
| 44 | + render: author => { |
| 45 | + return <UserCell user={author} /> |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + title: '社区', |
| 50 | + width: 150, |
| 51 | + dataIndex: 'communities', |
| 52 | + align: 'center', |
| 53 | + render: (communities, record) => { |
| 54 | + return ( |
| 55 | + <CommunityCell |
| 56 | + array={communities} |
| 57 | + source={record} |
| 58 | + thread="POST" |
| 59 | + onDelete={logic.unsetCommunity} |
| 60 | + onAdd={logic.setCommunity} |
| 61 | + withSetter |
| 62 | + /> |
| 63 | + ) |
| 64 | + }, |
| 65 | + }, |
| 66 | + { |
| 67 | + title: '标签', |
| 68 | + width: 250, |
| 69 | + dataIndex: 'tags', |
| 70 | + align: 'center', |
| 71 | + render: (tags, record) => ( |
| 72 | + <TagsCell |
| 73 | + thread="POST" |
| 74 | + source={record} |
| 75 | + onDelete={logic.unsetTag} |
| 76 | + onAdd={logic.setTag} |
| 77 | + /> |
| 78 | + ), |
| 79 | + }, |
| 80 | + { |
| 81 | + title: '浏览', |
| 82 | + width: 100, |
| 83 | + dataIndex: 'views', |
| 84 | + align: 'center', |
| 85 | + }, |
| 86 | + { |
| 87 | + title: '评论数', |
| 88 | + width: 100, |
| 89 | + dataIndex: 'commentsCount', |
| 90 | + align: 'center', |
| 91 | + }, |
| 92 | + { |
| 93 | + title: '评论参与', |
| 94 | + width: 150, |
| 95 | + dataIndex: 'commentsParticipatorsCount', |
| 96 | + align: 'center', |
| 97 | + }, |
| 98 | + { |
| 99 | + title: '创建时间', |
| 100 | + width: 150, |
| 101 | + dataIndex: 'insertedAt', |
| 102 | + align: 'center', |
| 103 | + render: text => { |
| 104 | + return <TimeAgo datetime={text} locale="zh_CN" /> |
| 105 | + }, |
| 106 | + }, |
| 107 | + { |
| 108 | + title: '上次更新', |
| 109 | + width: 150, |
| 110 | + dataIndex: 'updatedAt', |
| 111 | + align: 'center', |
| 112 | + render: text => { |
| 113 | + return <TimeAgo datetime={text} locale="zh_CN" /> |
| 114 | + }, |
| 115 | + }, |
| 116 | + { |
| 117 | + title: '操作', |
| 118 | + width: 200, |
| 119 | + dataIndex: '', |
| 120 | + align: 'center', |
| 121 | + render: (text, record) => { |
| 122 | + return ( |
| 123 | + <OperationWrapper> |
| 124 | + <Button |
| 125 | + size="small" |
| 126 | + type="primary" |
| 127 | + ghost |
| 128 | + onClick={logic.onEdit.bind(this, record)} |
| 129 | + > |
| 130 | + 编辑 |
| 131 | + </Button> |
| 132 | + <Space right="10px" /> |
| 133 | + <Button |
| 134 | + size="small" |
| 135 | + type="red" |
| 136 | + ghost |
| 137 | + onClick={logic.onDelete.bind(this, record)} |
| 138 | + > |
| 139 | + 删除 |
| 140 | + </Button> |
| 141 | + </OperationWrapper> |
| 142 | + ) |
| 143 | + }, |
| 144 | + }, |
| 145 | +] |
| 146 | + |
| 147 | +const ReposContent = ({ data, restProps: { communitiesLoading } }) => ( |
| 148 | + <React.Fragment> |
| 149 | + {data ? ( |
| 150 | + <div> |
| 151 | + <Table |
| 152 | + columns={columns} |
| 153 | + dataSource={data.entries} |
| 154 | + scroll={{ x: 2000 }} |
| 155 | + loading={TableLoading(communitiesLoading)} |
| 156 | + pagination={false} |
| 157 | + /> |
| 158 | + <Pagi |
| 159 | + left="-10px" |
| 160 | + pageNumber={data.pageNumber} |
| 161 | + pageSize={data.pageSize} |
| 162 | + totalCount={data.totalCount} |
| 163 | + onChange={logic.loadPosts} |
| 164 | + /> |
| 165 | + </div> |
| 166 | + ) : null} |
| 167 | + </React.Fragment> |
| 168 | +) |
| 169 | + |
| 170 | +export default ReposContent |
0 commit comments