mutations.js
2.6 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as Types from './types';
import {getArticleImageSize} from 'utils/image-handler';
import { get, first } from 'lodash';
export default {
[Types.FETCH_ARTICLE_DETAIL_REQUEST](state) {
state.fetchArticleList = true;
},
[Types.FETCH_ARTICLE_DETAIL_SUCCESS](state, {data, page}) {
state.fetchArticleList = false;
if (page === 1) {
state.articleList = [];
}
state.articleList = state.articleList.concat(data);
state.articleList.forEach((item, index) => {
const imageBlocks = get(item, 'blockList', []).filter(block => block.templateKey === 'image');
const firstImage = first(imageBlocks);
if (firstImage) {
let {width, height} = getArticleImageSize(firstImage);
firstImage.width = width;
firstImage.height = height;
}
item.index = index;
});
data.forEach(item => {
get(item, 'productList', []).forEach(product => {
product.favorite = false;
});
});
},
[Types.FETCH_ARTICLE_DETAIL_FAILD](state) {
state.fetchArticleList = false;
},
[Types.FETCH_ARTICLE_PRODUCT_SUCCESS](state, {articles, favs, articleProductType}) {
articles.forEach(article => {
if (article.articleProductType === articleProductType) {
get(article, 'productList', []).forEach(product => {
const find = favs.find(f => f.id === product.productId);
if (find) {
product.favorite = find.favorite;
}
});
}
});
},
[Types.FETCH_GUANG_SUCCESS](state, data) {
state.articleDetail = data;
},
[Types.CHANGE_AUTHOR_FOLLOW](state, {authorUid, follow}) {
state.articleList.forEach(article => {
if (article.authorUid === authorUid) {
article.hasAttention = follow ? 'Y' : 'N';
}
});
},
[Types.CHANGE_AUTHOR_TOPIC_FOLLOW](state, {authorUid, follow}) {
state.articleListByTopic.forEach(article => {
if (article.authorUid === authorUid) {
article.hasAttention = follow ? 'Y' : 'N';
}
});
},
[Types.FETCH_ARTICLE_TOPIC_REQUEST](state, {page}) {
state.fetchArticleListByTopic = true;
if (page === 1) {
state.articleLastedTimeByTopic = 0;
state.articleListByTopic = [];
}
},
[Types.FETCH_ARTICLE_TOPIC_SUCCESS](state, {data}) {
state.fetchArticleListByTopic = false;
state.articleListByTopic = state.articleListByTopic.concat(data.detailList);
state.articleLastedTimeByTopic = data.lastedTime;
state.articleListByTopic.forEach((item, index) => {
item.index = index;
});
},
[Types.FETCH_ARTICLE_TOPIC_FAILD](state) {
state.fetchArticleListByTopic = false;
}
};