File tree 5 files changed +26
-15
lines changed
5 files changed +26
-15
lines changed Original file line number Diff line number Diff line change 1
1
export default {
2
+ testData : ( data ) => {
3
+ return {
4
+ type : 'GET_START' ,
5
+ params :data
6
+ }
7
+ } ,
2
8
getIndexData : ( data ) => {
3
- console . log ( 11111 ) ;
4
9
return {
5
10
type : 'GET_INDEXLIST' ,
6
11
params :data
Original file line number Diff line number Diff line change 1
- export default ( state = [ ] , action ) => {
2
- console . log ( 3333 ) ;
1
+ export default ( state , action ) => {
2
+ console . log ( action ) ;
3
3
switch ( action . type ) {
4
4
case 'GET_START' :
5
5
return { indexList :[ ] , status : 'GET_START' }
6
6
case "GET_INDEXLIST" :
7
- if ( action . more ) {
7
+ let { params= { } } = action
8
+ if ( params . more ) {
8
9
let arr = [ ...state , ...action . data ]
9
10
return { indexList :arr , status : 'LOADING_STATE' }
10
11
} else {
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ import { put, takeEvery } from 'redux-saga/effects'
2
2
import axios from 'axios'
3
3
4
4
function * getIndexData ( params ) {
5
- console . log ( params ) ;
6
5
try {
7
- const res = yield axios . get ( '/v1/topics' , { params :params } )
6
+ const res = yield axios . get ( '/v1/topics' , { params :params . params } )
8
7
9
8
if ( res . status == 200 ) {
10
9
yield put ( {
11
10
type : "GET_INDEXLIST" ,
12
- data : res . data . data
11
+ data : res . data . data ,
12
+ params :params . params
13
13
} ) ;
14
14
}
15
15
} catch ( e ) {
@@ -19,5 +19,5 @@ function* getIndexData(params) {
19
19
}
20
20
21
21
export default function * fecthData ( ) {
22
- yield takeEvery ( "GET_INDEXLIST " , getIndexData )
22
+ yield takeEvery ( "GET_START " , getIndexData )
23
23
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ global.delcookie = function(name){
27
27
if ( cval != null ) document . cookie = name + "=" + cval + "; path=/;expires=" + exp . toGMTString ( ) ;
28
28
}
29
29
30
- global . isScrolling = function ( ) {
30
+ global . isBottom = function ( ) {
31
31
const { scrollTop } = document . documentElement || document . body
32
32
const { clientHeight, scrollHeight } = document . documentElement ;
33
33
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class App extends React.Component {
21
21
componentDidMount ( ) {
22
22
let { dispatch, match } = this . props
23
23
24
- dispatch ( actionCreator . getIndexData ( this . params ) ) ;
24
+ dispatch ( actionCreator . testData ( this . params ) ) ;
25
25
setInterval ( ( ) => {
26
26
this . halderScroll ( )
27
27
} , 1000 )
@@ -35,27 +35,32 @@ class App extends React.Component {
35
35
this . params . tab = tab
36
36
this . params . page = 1
37
37
this . params . more = false
38
- dispatch ( actionCreator . getIndexData ( this . params ) ) ;
38
+ dispatch ( actionCreator . testData ( this . params ) ) ;
39
39
} else {
40
- this . isLoad = true
40
+ setTimeout ( ( ) => {
41
+ this . isLoad = true
42
+ } , 2000 ) ;
41
43
}
42
44
43
45
}
44
46
45
47
46
48
halderScroll ( ) {
47
49
let { dispatch } = this . props
50
+ let timer = null
48
51
49
- if ( isScrolling ( ) && this . isLoad ) {
52
+
53
+ if ( isBottom ( ) && this . isLoad ) {
54
+ console . log ( 1111 ) ;
50
55
this . params . more = true
51
56
this . params . page ++
52
- dispatch ( actionCreator . getIndexData ( this . params ) ) ;
57
+ dispatch ( actionCreator . testData ( this . params ) ) ;
53
58
this . isLoad = false
54
59
}
60
+
55
61
}
56
62
57
63
render ( ) {
58
- console . log ( this . props ) ;
59
64
let { indexList = [ ] } = this . props
60
65
61
66
return (
You can’t perform that action at this time.
0 commit comments