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
| /* eslint-disable */
| /**柯礼钦
| * 4/3/2020, 9:57:26 AM
| * doc comment for the file goes here
| */
|
| /** 表格公用组件 */
| import React, { ReactNode, ReactEventHandler, Component } from 'react';
| import { Table } from 'antd';
| import './index.scss';
| import fetch from '../../../api/request';
|
| export default class TableView extends Component {
| constructor(props) {
| super(props);
| this.config = {
| };
| this.state = {
| tableData: [],
| totalElements: 0,
| pageSize: 10,
| page: 1,
| loading: false
| };
| }
|
| componentDidMount() {
| let { page = 1, size } = this.props.formData;
| this.loadData(page, size);
| }
|
| loadData = (page, size) => {
| let { formData, extraFromData, url } = this.props;
| this.setState({
| loading: true,
| });
| fetch({
| url,
| params: {
| ...formData,
| ...extraFromData,
| page,
| size
| }
| }).then(res => {
| if (res && res)
| if (res) {
| if (res.content) {
| res.content = res.content.map(({ ...a }, idx) => ({
| ...a,
| index: idx + 1 + 10 * (page - 1),
| key: idx,
| }));
| this.setState({
| tableData: res ? res.content : [],
| loading: false,
| totalElements: res ? res.totalElements : 0,
| });
| } else {
| res = res.map(({ ...a }, idx) => ({
| ...a,
| index: idx + 1 + 10 * (page - 1),
| key: idx,
| }));
| this.setState({
| tableData: res,
| loading: false,
| })
| }
| }
| });
| };
|
| pageChange = (page, size) => {
| this.props.setFormData({
| ...this.props.formData,
| page
| });
| this.loadData(page, size);
| };
|
| onShowSizeChange = (current, size) => {
| this.props.setFormData({
| ...this.props.formData,
| page: 1,
| size
| });
| this.loadData(1, size);
| };
|
| itemRender = (current, type, originalElement) => {
| if (type === 'prev') {
| return <span>上一页 </span>;
| } else if (type === 'next') {
| return <span> 下一页</span>;
| }
| return originalElement;
| };
|
| onSetDataSource = ({ index, data }, callBack) => {
| console.log(index, data);
| let { tableData } = this.state;
| tableData[index] = data;
| this.setState({
| tableData
| })
| }
|
| render() {
| const { columns, rowSelection, showPagination = true } = this.props;
| const { page, size, } = this.props.formData;
| return (
| <div className="table-view-main">
| <Table
| rowSelection={rowSelection || null}
| size="middle"
| className="rowColor"
| dataSource={this.state.tableData}
| loading={{ spinning: this.state.loading }}
| columns={columns}
| pagination={showPagination ? {
| pageSize: Number(size),
| onChange: this.pageChange,
| total: this.state.totalElements,
| showSizeChanger: true,
| onShowSizeChange: this.onShowSizeChange,
| showTotal: (total, range) => `共${total}条记录 `,
| // itemRender: this.itemRender,
| showQuickJumper: true,
| defaultCurrent: 1,
| current: Number(page),
| } : false} />
| </div>
| )
| }
| }
|
|