fulltext.js
1.28 KB
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
import {
FETCH_FULLTEXT_FAILURE,
FETCH_FULLTEXT_REQUEST,
FETCH_FULLTEXT_SUCCESS
} from './types';
import api from 'common/api';
export default {
state: {
fetching: false,
fulltexts: [],
searchParams: {
page: 1,
count: 10
},
count: 0
},
mutations: {
[FETCH_FULLTEXT_REQUEST](state, params) {
state.fetching = true;
state.searchParams = Object.assign(state.searchParams, params);
},
[FETCH_FULLTEXT_FAILURE](state) {
state.fetching = false;
},
[FETCH_FULLTEXT_SUCCESS](state, params) {
state.fetching = false;
state.fulltexts = params.data;
state.count = params.count;
}
},
actions: {
[FETCH_FULLTEXT_REQUEST]({commit, state}, params) {
commit(FETCH_FULLTEXT_REQUEST, params);
return api.get('/list', state.searchParams).then(res => {
if (res.code === 200) {
commit(FETCH_FULLTEXT_SUCCESS, {data: res.data, count: res.count});
} else {
commit(FETCH_FULLTEXT_FAILURE);
}
}, () => {
commit(FETCH_FULLTEXT_FAILURE);
});
}
}
};