forked from zuiidea/antd-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.js
48 lines (44 loc) · 1.05 KB
/
post.js
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
import modelExtend from 'dva-model-extend'
import { query } from 'services/posts'
import { pageModel } from 'models/common'
import queryString from 'query-string'
export default modelExtend(pageModel, {
namespace: 'post',
subscriptions: {
setup ({ dispatch, history }) {
history.listen((location) => {
if (location.pathname === '/post') {
dispatch({
type: 'query',
payload: {
status: 2,
...queryString.parse(location.search),
},
})
}
})
},
},
effects: {
* query ({
payload,
}, { call, put }) {
const data = yield call(query, payload)
if (data.success) {
yield put({
type: 'querySuccess',
payload: {
list: data.data,
pagination: {
current: Number(payload.page) || 1,
pageSize: Number(payload.pageSize) || 10,
total: data.total,
},
},
})
} else {
throw data
}
},
},
})