PaginationWrap.js
2.4 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
import React,{PropTypes} from 'react';
import {connect} from 'react-redux';
import { Field, reduxForm,formValueSelector,getFormValues,change} from 'redux-form';
import { Row,Col,Input,Pagination } from 'antd';
import cx from 'classnames';
const InputGroup = Input.Group;
class PaginationWrap extends React.Component {
constructor(props) {
super(props);
this.onChange=this.onChange.bind(this);
this.state={
}
}
static propTypes = {
onChange: PropTypes.func,
formName:PropTypes.string,
style:PropTypes.object,
pageSizeOptions:PropTypes.array,
}
static defaultProps={
onChange:(values)=>{
},
formName:'search_list',
style:{},
pageSizeOptions:['10' , '25' , '50' , '100']
}
componentDidMount(){
}
componentWillReceiveProps(nextProps){
}
componentWillUnmount(){
}
onChange(page,limit){
const {myValues={},dispatch,formType,formName}=this.props;
dispatch(change(formType?formType:formName,'offset',((page-1)*limit)))
this.props.onChange({
...myValues,
offset:((page-1)*limit),
from: 'pagination',
})
}
onShowSizeChange = (current, pageSize) => {
const {myValues={},dispatch,formType,formName}=this.props;
dispatch(change(formType?formType:formName,'offset',((current-1)*pageSize)))
dispatch(change(formType?formType:formName,'limit',pageSize))
this.props.onChange({
...myValues,
offset:((current-1)*pageSize),
limit: pageSize,
from: 'pagination',
})
}
render(){
const {myValues={},style={} , pageSizeOptions=[] } = this.props;
const {total_count} = myValues;
return(
<Pagination style={{textAlign:'right',marginTop:'15px',...style}}
onChange={this.onChange}
current={myValues.offset?parseInt(myValues.offset/myValues.limit)+1:1}
pageSize={myValues.limit}
total={myValues.total_count}
showTotal={(total_count, range) => `当前: ${range[0]}-${range[1]} 条 共 ${total_count} 条`}
showSizeChanger
onShowSizeChange={this.onShowSizeChange}
showQuickJumper
// pageSizeOptions={['10', '20', '30', '40', '50']}
pageSizeOptions={pageSizeOptions}
/>
)
}
}
const mapState = (state,props) => {
const { formName = 'search_list' } = props;
return {
myValues: getFormValues(formName)(state)
}
};
export default connect(mapState, null, null, { withRef: true })(PaginationWrap);