Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
d8e9f225
Commit
d8e9f225
authored
Nov 03, 2017
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve search saga and loading logic
parent
f50867b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
48 deletions
+21
-48
src/models/list.js
src/models/list.js
+12
-8
src/routes/List/SearchList.js
src/routes/List/SearchList.js
+9
-40
No files found.
src/models/list.js
View file @
d8e9f225
...
@@ -5,35 +5,33 @@ export default {
...
@@ -5,35 +5,33 @@ export default {
state
:
{
state
:
{
list
:
[],
list
:
[],
loading
:
true
,
loading
:
false
,
cursor
:
0
,
},
},
effects
:
{
effects
:
{
*
fetch
({
payload
,
callback
},
{
call
,
put
})
{
*
fetch
({
payload
},
{
call
,
put
})
{
yield
put
({
yield
put
({
type
:
'
changeLoading
'
,
type
:
'
changeLoading
'
,
payload
:
true
,
payload
:
true
,
});
});
const
response
=
yield
call
(
queryFakeList
,
payload
);
const
response
=
yield
call
(
queryFakeList
,
payload
);
yield
put
({
yield
put
({
type
:
'
save
'
,
type
:
'
appendList
'
,
payload
:
Array
.
isArray
(
response
)
?
response
:
[],
payload
:
Array
.
isArray
(
response
)
?
response
:
[],
});
});
yield
put
({
yield
put
({
type
:
'
changeLoading
'
,
type
:
'
changeLoading
'
,
payload
:
false
,
payload
:
false
,
});
});
if
(
callback
)
{
callback
();
}
},
},
},
},
reducers
:
{
reducers
:
{
save
(
state
,
action
)
{
appendList
(
state
,
action
)
{
return
{
return
{
...
state
,
...
state
,
list
:
action
.
payload
,
list
:
state
.
list
.
concat
(
action
.
payload
)
,
};
};
},
},
changeLoading
(
state
,
action
)
{
changeLoading
(
state
,
action
)
{
...
@@ -42,5 +40,11 @@ export default {
...
@@ -42,5 +40,11 @@ export default {
loading
:
action
.
payload
,
loading
:
action
.
payload
,
};
};
},
},
updateCursor
(
state
,
action
)
{
return
{
...
state
,
loading
:
action
.
payload
,
};
},
},
},
};
};
src/routes/List/SearchList.js
View file @
d8e9f225
...
@@ -12,25 +12,15 @@ import styles from './SearchList.less';
...
@@ -12,25 +12,15 @@ import styles from './SearchList.less';
const
{
Option
}
=
Select
;
const
{
Option
}
=
Select
;
const
FormItem
=
Form
.
Item
;
const
FormItem
=
Form
.
Item
;
const
pageSize
=
5
;
@
Form
.
create
()
@
Form
.
create
()
@
connect
(
state
=>
({
@
connect
(
state
=>
({
list
:
state
.
list
,
list
:
state
.
list
,
}))
}))
export
default
class
SearchList
extends
Component
{
export
default
class
SearchList
extends
Component
{
state
=
{
count
:
3
,
showLoadMore
:
true
,
loadingMore
:
false
,
}
componentDidMount
()
{
componentDidMount
()
{
const
{
count
}
=
this
.
state
;
this
.
fetchMore
();
this
.
props
.
dispatch
({
type
:
'
list/fetch
'
,
payload
:
{
count
,
},
});
}
}
setOwner
=
()
=>
{
setOwner
=
()
=>
{
...
@@ -40,30 +30,11 @@ export default class SearchList extends Component {
...
@@ -40,30 +30,11 @@ export default class SearchList extends Component {
});
});
}
}
handleLoadMore
=
()
=>
{
fetchMore
=
()
=>
{
const
{
count
}
=
this
.
state
;
const
nextCount
=
count
+
5
;
this
.
setState
({
count
:
nextCount
,
loadingMore
:
true
,
});
this
.
props
.
dispatch
({
this
.
props
.
dispatch
({
type
:
'
list/fetch
'
,
type
:
'
list/fetch
'
,
payload
:
{
payload
:
{
count
:
nextCount
,
count
:
pageSize
,
},
callback
:
()
=>
{
this
.
setState
({
loadingMore
:
false
,
});
// fack count
if
(
nextCount
<
10
)
{
this
.
setState
({
showLoadMore
:
false
,
});
}
},
},
});
});
}
}
...
@@ -86,7 +57,6 @@ export default class SearchList extends Component {
...
@@ -86,7 +57,6 @@ export default class SearchList extends Component {
}
}
render
()
{
render
()
{
const
{
showLoadMore
,
loadingMore
}
=
this
.
state
;
const
{
form
,
list
:
{
list
,
loading
}
}
=
this
.
props
;
const
{
form
,
list
:
{
list
,
loading
}
}
=
this
.
props
;
const
{
getFieldDecorator
}
=
form
;
const
{
getFieldDecorator
}
=
form
;
...
@@ -165,11 +135,10 @@ export default class SearchList extends Component {
...
@@ -165,11 +135,10 @@ export default class SearchList extends Component {
},
},
};
};
const
loadMore
=
showLoadMore
?
(
const
loadMore
=
list
.
length
>
0
?
(
<
div
style
=
{{
textAlign
:
'
center
'
,
marginTop
:
16
}}
>
<
div
style
=
{{
textAlign
:
'
center
'
,
marginTop
:
16
}}
>
<
Button
onClick
=
{
this
.
handleLoadMore
}
style
=
{{
paddingLeft
:
48
,
paddingRight
:
48
}}
>
<
Button
onClick
=
{
this
.
fetchMore
}
style
=
{{
paddingLeft
:
48
,
paddingRight
:
48
}}
>
{
loadingMore
&&
(
<
span
><
Icon
type
=
"
loading
"
/>
ε θ½½δΈ
...
<
/span>
)
}
{
loading
?
<
span
><
Icon
type
=
"
loading
"
/>
ε θ½½δΈ
...
<
/span> : 'ε θ½½ζ΄ε€'
}
{
!
loadingMore
&&
(
<
span
>
ε θ½½ζ΄ε€
<
/span>
)
}
<
/Button
>
<
/Button
>
<
/div
>
<
/div
>
)
:
null
;
)
:
null
;
...
@@ -286,7 +255,7 @@ export default class SearchList extends Component {
...
@@ -286,7 +255,7 @@ export default class SearchList extends Component {
>
>
<
List
<
List
size
=
"
large
"
size
=
"
large
"
loading
=
{
!
loadingMore
&&
loading
}
loading
=
{
list
.
length
===
0
?
loading
:
false
}
rowKey
=
"
id
"
rowKey
=
"
id
"
itemLayout
=
"
vertical
"
itemLayout
=
"
vertical
"
loadMore
=
{
loadMore
}
loadMore
=
{
loadMore
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment