forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleTable.jsx
More file actions
170 lines (156 loc) · 3.66 KB
/
SimpleTable.jsx
File metadata and controls
170 lines (156 loc) · 3.66 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { Component } from 'react';
import { Table, Pagination } from '@icedesign/base';
import IceContainer from '@icedesign/container';
import IceImg from '@icedesign/img';
import DataBinder from '@icedesign/data-binder';
import IceLabel from '@icedesign/label';
import './SimpleTable.scss';
@DataBinder({
tableData: {
// 详细请求配置请参见 https://github.com/axios/axios
url: '/mock/simple-table-list.json',
params: {
page: 1,
},
defaultBindingData: {
list: [],
total: 100,
pageSize: 10,
currentPage: 1,
},
},
})
export default class SimpleTable extends Component {
static displayName = 'SimpleTable';
static propTypes = {};
static defaultProps = {};
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
this.fetchData({
page: 1,
});
}
fetchData = ({ page }) => {
this.props.updateBindingData('tableData', {
data: {
page,
},
});
};
renderTitle = (value, index, record) => {
return (
<div
style={{
display: 'flex',
flexDirection: 'row',
}}
>
<div>
<IceImg src={record.cover} width={48} height={48} />
</div>
<span
style={{
marginLeft: '10px',
lineHeight: '20px',
}}
>
{record.title}
</span>
</div>
);
};
editItem = (record, e) => {
e.preventDefault();
// todo
console.log('record', record);
};
renderOperations = (value, index, record) => {
return (
<div className="simple-table-operation" style={{ lineHeight: '28px' }}>
<a
href="#"
target="_blank"
onClick={() => {
this.editItem(record);
}}
>
解决
</a>
<a href="#" target="_blank">
详情
</a>
<a href="#" target="_blank">
分类
</a>
</div>
);
};
renderStatus = (value) => {
return (
<IceLabel inverse={false} status="default">
{value}
</IceLabel>
);
};
changePage = (currentPage) => {
this.fetchData({
page: currentPage,
});
};
render() {
const tableData = this.props.bindingData.tableData;
return (
<div className="simple-table">
<IceContainer>
<Table
dataSource={tableData.list}
isLoading={tableData.__loading} // eslint-disable-line
className="basic-table"
hasBorder={false}
>
<Table.Column
title="问题描述"
cell={this.renderTitle}
width={320}
/>
<Table.Column title="问题分类" dataIndex="type" width={85} />
<Table.Column
title="发布时间"
dataIndex="publishTime"
width={150}
/>
<Table.Column
title="状态"
dataIndex="publishStatus"
width={85}
cell={this.renderStatus}
/>
<Table.Column
title="操作"
dataIndex="operation"
width={150}
cell={this.renderOperations}
/>
</Table>
<div style={styles.paginationWrapper}>
<Pagination
current={tableData.currentPage}
pageSize={tableData.pageSize}
total={tableData.total}
onChange={this.changePage}
/>
</div>
</IceContainer>
</div>
);
}
}
const styles = {
paginationWrapper: {
textAlign: 'right',
paddingTop: '26px',
},
};