forked from huge/frontEnd/hugeOA

Mr Ke
2020-10-20 6bf92751fe8dfa0624285268968a1fd7a8a7e7e5
src/components/common/TableView/index.jsx
@@ -25,7 +25,7 @@
    }
    componentDidMount() {
        let { page, size } = this.props.formData;
        let { page = 1, size } = this.props.formData;
        this.loadData(page, size);
    }
@@ -43,18 +43,31 @@
                size
            }
        }).then(res => {
            if (res) {
                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,
            });
            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,
                        })
                    }
                }
        });
    };
@@ -84,19 +97,29 @@
        return originalElement;
    };
    onSetDataSource = ({ index, data }, callBack) => {
        console.log(index, data);
        let { tableData } = this.state;
        tableData[index] = data;
        this.setState({
            tableData
        })
    }
    render() {
        const { columns, rowSelection } = this.props;
        const { page, size } = this.props.formData;
        const { columns, rowSelection, showPagination = true, rowClassName = '' } = this.props;
        const { page, size, } = this.props.formData;
        return (
            <div className="table-view-main">
                <Table
                    rowClassName={rowClassName}
                    rowSelection={rowSelection || null}
                    size="middle"
                    className="rowColor"
                    dataSource={this.state.tableData}
                    loading={{ spinning: this.state.loading }}
                    columns={columns}
                    pagination={{
                    pagination={showPagination ? {
                        pageSize: Number(size),
                        onChange: this.pageChange,
                        total: this.state.totalElements,
@@ -107,7 +130,7 @@
                        showQuickJumper: true,
                        defaultCurrent: 1,
                        current: Number(page),
                    }} />
                    } : false} />
            </div>
        )
    }