forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTabTable.jsx
More file actions
132 lines (121 loc) · 2.96 KB
/
TabTable.jsx
File metadata and controls
132 lines (121 loc) · 2.96 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
import React, { Component } from 'react';
import IceContainer from '@icedesign/container';
import { Tab } from '@icedesign/base';
import axios from 'axios';
import CustomTable from './components/CustomTable';
import EditDialog from './components/EditDialog';
import DeleteBalloon from './components/DeleteBalloon';
import './TabTable.scss';
const TabPane = Tab.TabPane;
const tabs = [
{ tab: '全部', key: 'all' },
{ tab: '已发布', key: 'inreview' },
{ tab: '审核中', key: 'released' },
{ tab: '已拒绝', key: 'rejected' },
];
export default class TabTable extends Component {
static displayName = 'TabTable';
static propTypes = {};
static defaultProps = {};
constructor(props) {
super(props);
this.state = {
dataSource: {},
tabKey: 'all',
};
this.columns = [
{
title: '标题',
dataIndex: 'title',
key: 'title',
},
{
title: '作者',
dataIndex: 'author',
key: 'author',
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
},
{
title: '发布时间',
dataIndex: 'date',
key: 'date',
},
{
title: '操作',
key: 'action',
render: (value, index, record) => {
return (
<span>
<EditDialog
index={index}
record={record}
getFormValues={this.getFormValues}
/>
<DeleteBalloon
handleRemove={() => this.handleRemove(value, index, record)}
/>
</span>
);
},
},
];
}
componentDidMount() {
axios
.get('/mock/tab-table.json')
.then((response) => {
console.log(response.data.data);
this.setState({
dataSource: response.data.data,
});
})
.catch((error) => {
console.log(error);
});
}
getFormValues = (dataIndex, values) => {
const { dataSource, tabKey } = this.state;
dataSource[tabKey][dataIndex] = values;
this.setState({
dataSource,
});
};
handleRemove = (value, index) => {
const { dataSource, tabKey } = this.state;
dataSource[tabKey].splice(index, index + 1);
this.setState({
dataSource,
});
};
handleTabChange = (key) => {
this.setState({
tabKey: key,
});
};
render() {
const { dataSource } = this.state;
return (
<div className="tab-table">
<IceContainer>
<Tab onChange={this.handleTabChange}>
{tabs.map((item) => {
return (
<TabPane tab={item.tab} key={item.key}>
<CustomTable
dataSource={dataSource[this.state.tabKey]}
columns={this.columns}
hasBorder={false}
/>
</TabPane>
);
})}
</Tab>
</IceContainer>
</div>
);
}
}