/
List.js
120 lines (113 loc) · 2.78 KB
/
List.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Table, Modal } from 'antd'
import { Link } from 'dva/router'
import { withI18n, Trans } from '@lingui/react'
import { DropOption } from 'components'
import { getMediaUrl } from 'utils/helpers'
import styles from './List.less'
const { confirm } = Modal
@withI18n()
class List extends PureComponent {
handleMenuClick = (record, e) => {
const { onDeleteItem, onEditItem, i18n } = this.props
if (e.key === '1') {
onEditItem(record)
} else if (e.key === '2') {
confirm({
title: i18n.t`Are you sure delete this record?`,
onOk() {
onDeleteItem(record._id)
},
})
}
}
render() {
const { onDeleteItem, onEditItem, i18n, ...tableProps } = this.props
const columns = [
{
title: i18n.t`Title`,
dataIndex: 'title',
fixed: 'left',
render: (text, record) => (
<Link to={`article/${record._id}`}>{text || record._id}</Link>
),
},
{
title: i18n.t`Cover`,
dataIndex: 'cover',
render: text => (
<img alt="cover" style={{ width: '100px' }} src={getMediaUrl(text)} />
),
},
{
title: i18n.t`Author`,
dataIndex: 'author',
},
{
title: i18n.t`Category`,
dataIndex: 'category.name',
},
{
title: i18n.t`Tags`,
dataIndex: 'tags',
render: text => (
<span>{Array.isArray(text) ? text.join('/') : ''}</span>
),
},
{
title: i18n.t`Comments`,
dataIndex: 'comments',
},
{
title: i18n.t`Views`,
dataIndex: 'viewNum',
},
{
title: i18n.t`CreateTime`,
dataIndex: 'createDate',
},
{
title: i18n.t`UpdateTime`,
dataIndex: 'updateDate',
},
{
title: <Trans>Operation</Trans>,
key: 'operation',
fixed: 'right',
render: (text, record) => {
return (
<DropOption
onMenuClick={e => this.handleMenuClick(record, e)}
menuOptions={[
{ key: '1', name: i18n.t`Update` },
{ key: '2', name: i18n.t`Delete` },
]}
/>
)
},
},
]
return (
<Table
{...tableProps}
pagination={{
...tableProps.pagination,
showTotal: total => i18n.t`Total ${total} Items`,
}}
bordered
scroll={{ x: 1400 }}
className={styles.table}
columns={columns}
simple
rowKey={record => record._id}
/>
)
}
}
List.propTypes = {
onDeleteItem: PropTypes.func,
onEditItem: PropTypes.func,
location: PropTypes.object,
}
export default List