mutations.js
1.55 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
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as Types from './types';
export default {
// 开始调用接口,方式重复调用
[Types.FETCH_ARTICLE_LIST_REQUEST](state) {
state.isFetchingArticleList = true;
},
// 调用失败
[Types.FETCH_ARTICLE_LIST_FAILED](state) {
state.isFetchingArticleList = false;
},
// 调用成功
[Types.FETCH_ARTICLE_LIST_SUCCESS](state, {result, reload}) {
console.log('reload');
state.isFetchingArticleList = false;
if (reload) {
state.articleList = [];
state.articleListInfo = {};
}
if (state.articleList.length === 0) {
state.articleList = result.data.list;
} else {
if (result.data.pageNo > state.articleListInfo.pageNo) {
state.articleList = state.articleList.concat(result.data.list);
}
}
delete result.data.list;
state.articleListInfo = result.data;
},
// 更新点赞
[Types.UPDATE_ARTICLE_PRAISE](state, {articleId, status, index}) {
let article = null;
if (index) {
article = state.articleList[index];
} else {
article = state.articleList.find(item => +item.articleId === +articleId);
}
if (article && article.articleId === parseInt(articleId, 10)) {
if (article.praiseCount === 0 && status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else if (article.praiseCount > 0) {
if (status === 0) {
article.praiseCount += 1;
article.hasPraised = 'Y';
} else {
article.praiseCount -= 1;
article.hasPraised = 'N';
}
}
}
}
};