|
@@ -1,7 +1,7 @@
|
1
|
1
|
import React from 'react'
|
2
|
2
|
import PropTypes from 'prop-types'
|
3
|
3
|
import classNames from 'classnames'
|
4
|
|
-import { notification } from 'antd'
|
|
4
|
+import { Spin, notification } from 'antd'
|
5
|
5
|
|
6
|
6
|
import SearchForm from './SearchForm'
|
7
|
7
|
import SearchBody from './SearchBody'
|
|
@@ -19,26 +19,39 @@ class SearchList extends React.PureComponent {
|
19
|
19
|
body: PropTypes.object,
|
20
|
20
|
pagination: PropTypes.object,
|
21
|
21
|
service: PropTypes.func,
|
|
22
|
+ reServe: PropTypes.func,
|
22
|
23
|
}
|
23
|
24
|
|
24
|
25
|
state = {
|
25
|
|
- defaultStorage: getStorageBuilder(window.Math.random().toString(36).substr(2)),
|
|
26
|
+ defaultStorage: this.props.storage || getStorageBuilder('PAGE-SearchList'),
|
26
|
27
|
dataSource: [],
|
27
|
|
- conditions: {},
|
|
28
|
+ conditions: this.getStorage().get('conditions') || {},
|
|
29
|
+ loadding: false,
|
28
|
30
|
pageConfig: {
|
29
|
|
- current: 1,
|
30
|
|
- pageSize: 10,
|
|
31
|
+ ...(this.getStorage().get('pagination') || { current: 1, pageSize: 10 }),
|
31
|
32
|
total: 0,
|
32
|
33
|
},
|
33
|
34
|
}
|
34
|
35
|
|
35
|
|
- handlePageChange = (page, pageSize) => {
|
|
36
|
+ componentDidMount () {
|
|
37
|
+ if (this.props.reServe) {
|
|
38
|
+ this.props.reServe(this.queryData)
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ getStorage() {
|
|
43
|
+ return this.props.storage || this.state.defaultStorage
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ handlePageChange = (current, pageSize) => {
|
|
47
|
+ this.getStorage().set('pagination', { current, pageSize: 10 })
|
|
48
|
+
|
36
|
49
|
this.setState(
|
37
|
50
|
(state) => ({
|
38
|
51
|
...state,
|
39
|
52
|
pageConfig: {
|
40
|
53
|
...state.pageConfig,
|
41
|
|
- current: page,
|
|
54
|
+ current,
|
42
|
55
|
pageSize,
|
43
|
56
|
}
|
44
|
57
|
}),
|
|
@@ -46,16 +59,32 @@ class SearchList extends React.PureComponent {
|
46
|
59
|
)
|
47
|
60
|
}
|
48
|
61
|
|
49
|
|
- handleSearchSubmit = (conditions) => {
|
|
62
|
+ repondToSearch = (conditions) => {
|
|
63
|
+ // 查询提交会重置页码
|
|
64
|
+ const { pageConfig } = this.state
|
|
65
|
+ const newPageConfig = { ...pageConfig, current: 1, total: 0 }
|
|
66
|
+
|
|
67
|
+ this.getStorage().set('conditions', conditions)
|
|
68
|
+ this.getStorage().set('pagination', newPageConfig)
|
|
69
|
+
|
50
|
70
|
this.setState(
|
51
|
71
|
(state) => ({
|
52
|
72
|
...state,
|
53
|
73
|
conditions,
|
|
74
|
+ pageConfig: newPageConfig,
|
54
|
75
|
}),
|
55
|
76
|
this.queryData,
|
56
|
77
|
)
|
57
|
78
|
}
|
58
|
79
|
|
|
80
|
+ handleSearchSubmit = (conditions) => {
|
|
81
|
+ this.repondToSearch(conditions)
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ handleSearchCancel = () => {
|
|
85
|
+ this.repondToSearch({})
|
|
86
|
+ }
|
|
87
|
+
|
59
|
88
|
queryData = () => {
|
60
|
89
|
if (this.props.service) {
|
61
|
90
|
const pageConfigProps = this.props.pagination || {}
|
|
@@ -65,6 +94,8 @@ class SearchList extends React.PureComponent {
|
65
|
94
|
|
66
|
95
|
const { conditions = {}, pageConfig } = this.state
|
67
|
96
|
|
|
97
|
+ this.setState({ loadding: true })
|
|
98
|
+
|
68
|
99
|
this.props.service({
|
69
|
100
|
...conditions,
|
70
|
101
|
...{
|
|
@@ -76,6 +107,7 @@ class SearchList extends React.PureComponent {
|
76
|
107
|
|
77
|
108
|
this.setState((state) => ({
|
78
|
109
|
...state,
|
|
110
|
+ loadding: false,
|
79
|
111
|
dataSource,
|
80
|
112
|
pageConfig: {
|
81
|
113
|
...state.pageConfig,
|
|
@@ -83,6 +115,7 @@ class SearchList extends React.PureComponent {
|
83
|
115
|
},
|
84
|
116
|
}))
|
85
|
117
|
}).catch((e) => {
|
|
118
|
+ this.setState({ loadding: false })
|
86
|
119
|
console.error(e)
|
87
|
120
|
})
|
88
|
121
|
}
|
|
@@ -101,16 +134,18 @@ class SearchList extends React.PureComponent {
|
101
|
134
|
...this.state.pageConfig,
|
102
|
135
|
}
|
103
|
136
|
|
104
|
|
- const storage = this.props.storage || this.state.defaultStorage
|
|
137
|
+ const storage = this.getStorage()
|
105
|
138
|
|
106
|
139
|
return (
|
107
|
140
|
<div className={Style['search-list']}>
|
108
|
141
|
<div className={Style['head']}>
|
109
|
|
- <SearchForm storage={storage} onSubmit={this.handleSearchSubmit} configs={this.props.search} />
|
|
142
|
+ <SearchForm storage={storage} onSubmit={this.handleSearchSubmit} onCancel={this.handleSearchCancel} configs={this.props.search} />
|
110
|
143
|
</div>
|
111
|
144
|
<div className={Style['body']}>
|
112
|
145
|
<BodyHeader storage={storage} title={this.props.title} actions={this.props.actions} />
|
113
|
|
- <SearchBody storage={storage} dataSource={this.state.dataSource} configs={this.props.body} />
|
|
146
|
+ <Spin spinning={this.state.loadding}>
|
|
147
|
+ <SearchBody storage={storage} dataSource={this.state.dataSource} configs={this.props.body} />
|
|
148
|
+ </Spin>
|
114
|
149
|
<BodyPagination storage={storage} onChange={this.handlePageChange} configs={pageConfig} />
|
115
|
150
|
</div>
|
116
|
151
|
</div>
|
|
@@ -119,7 +154,7 @@ class SearchList extends React.PureComponent {
|
119
|
154
|
}
|
120
|
155
|
|
121
|
156
|
function withSearchList (configs = {}) {
|
122
|
|
- const cacheKey = `${configs.name || 'SearchList'}-${window.Math.random().toString(36).substr(2)}`
|
|
157
|
+ const cacheKey = `PAGE-${configs.name || 'SearchList'}`
|
123
|
158
|
const storage = getStorageBuilder(cacheKey)
|
124
|
159
|
|
125
|
160
|
return React.forwardRef((props, ref) => {
|