Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
admin-localhome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
localhome
admin-localhome
Commits
f511a773
Commit
f511a773
authored
Feb 22, 2018
by
chencheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4. Generate users model and service
parent
cb7a9c9e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
10 deletions
+51
-10
users.js
src/pages/users/models/users.js
+29
-0
users.js
src/pages/users/services/users.js
+5
-0
request.js
src/utils/request.js
+17
-10
No files found.
src/pages/users/models/users.js
0 → 100644
View file @
f511a773
import
*
as
usersService
from
'../services/users'
;
export
default
{
namespace
:
'users'
,
state
:
{
list
:
[],
total
:
null
,
},
reducers
:
{
save
(
state
,
{
payload
:
{
data
:
list
,
total
}
})
{
return
{
...
state
,
list
,
total
};
},
},
effects
:
{
*
fetch
({
payload
:
{
page
}
},
{
call
,
put
})
{
const
{
data
,
headers
}
=
yield
call
(
usersService
.
fetch
,
{
page
});
yield
put
({
type
:
'save'
,
payload
:
{
data
,
total
:
headers
[
'x-total-count'
]
}
});
},
},
subscriptions
:
{
setup
({
dispatch
,
history
})
{
return
history
.
listen
(({
pathname
,
query
})
=>
{
if
(
pathname
===
'/users'
)
{
dispatch
({
type
:
'fetch'
,
payload
:
query
});
}
});
},
},
};
src/pages/users/services/users.js
0 → 100644
View file @
f511a773
import
request
from
'../../../utils/request'
;
export
function
fetch
({
page
=
1
})
{
return
request
(
`/api/users?_page=
${
page
}
&_limit=5`
);
}
src/utils/request.js
View file @
f511a773
import
fetch
from
'dva/fetch'
;
import
fetch
from
'dva/fetch'
;
function
parseJSON
(
response
)
{
return
response
.
json
();
}
function
checkStatus
(
response
)
{
function
checkStatus
(
response
)
{
if
(
response
.
status
>=
200
&&
response
.
status
<
300
)
{
if
(
response
.
status
>=
200
&&
response
.
status
<
300
)
{
return
response
;
return
response
;
...
@@ -21,10 +17,21 @@ function checkStatus(response) {
...
@@ -21,10 +17,21 @@ function checkStatus(response) {
* @param {object} [options] The options we want to pass to "fetch"
* @param {object} [options] The options we want to pass to "fetch"
* @return {object} An object containing either "data" or "err"
* @return {object} An object containing either "data" or "err"
*/
*/
export
default
function
request
(
url
,
options
)
{
export
default
async
function
request
(
url
,
options
)
{
return
fetch
(
url
,
options
)
const
response
=
await
fetch
(
url
,
options
);
.
then
(
checkStatus
)
.
then
(
parseJSON
)
checkStatus
(
response
);
.
then
(
data
=>
({
data
}))
.
catch
(
err
=>
({
err
}));
const
data
=
await
response
.
json
();
const
ret
=
{
data
,
headers
:
{},
};
if
(
response
.
headers
.
get
(
'x-total-count'
))
{
ret
.
headers
[
'x-total-count'
]
=
response
.
headers
.
get
(
'x-total-count'
);
}
return
ret
;
}
}
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