actions.js
5.15 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import * as Types from './types';
import { get } from 'lodash';
import * as guangProcess from './guangProcess';
export default {
async fetchArticleList({ commit }, { articleId, authorUid, authorType, type, limit = 5, page = 1 }) {
commit(Types.FETCH_ARTICLE_LIST_REQUEST, {refresh: page === 1});
let api;
if (type === 'fav') {
api = '/api/grass/userFavouriteArticleDetail';
} else if (type === 'publish') {
api = '/api/grass/userPublishedArticleDetail';
} else {
api = '/api/grass/columnArticleDetail';
}
const result = await this.$api.get(api, {
articleId,
limit,
page,
authorUid,
authorType,
columnType: 1001
});
if (result && result.code === 200) {
if (!result.data.detailList) {
result.data.detailList = [];
}
commit(Types.FETCH_ARTICLE_LIST_SUCCESS, {
data: result.data.detailList,
});
} else {
commit(Types.FETCH_ARTICLE_LIST_FAILD);
}
return result;
},
async fetchArticleProductFavs({commit}, {articles}) {
const products = [], ufoProducts = [];
articles.forEach(article => {
get(article, 'productList', []).forEach(product => {
if (article.articleProductType === 1) {
products.push(product.productId);
} else if (article.articleProductType === 2) {
ufoProducts.push(product.productId);
}
});
});
if (products.length) {
const result = await this.$api.get('/api/favorite/batchCheckIsFavorite', {
favIds: products.join(','),
type: 'product'
});
if (result.code === 200) {
if (!result.data) {
result.data = [];
}
commit(Types.FETCH_ARTICLE_PRODUCT_SUCCESS, {articles, favs: result.data, articleProductType: 1});
}
}
if (ufoProducts.length) {
const result = await this.$api.get('/api/ufo/user/isFavoriteBatch', {
productIds: ufoProducts.join(','),
});
if (result.code === 200) {
if (!result.data) {
result.data = [];
}
commit(Types.FETCH_ARTICLE_PRODUCT_SUCCESS, {articles, favs: result.data, articleProductType: 2});
}
}
},
async fetchArticleListByTopic({commit, state}, {labelId, limit = 5, page = 1}) {
commit(Types.FETCH_ARTICLE_TOPIC_REQUEST, {page});
const result = await this.$api.get('/api/grass/labelRealtedArticleDetail', {
labelId,
limit,
page,
lastedTime: state.articleLastedTimeByTopic || void 0
});
if (result && result.code === 200) {
if (!result.data.detailList) {
result.data.detailList = [];
}
commit(Types.FETCH_ARTICLE_TOPIC_SUCCESS, {
data: result.data,
page
});
} else {
commit(Types.FETCH_ARTICLE_TOPIC_FAILD);
}
return result;
},
async getDetail({ commit }, { article_id, grass_id }) {
let result = {
getAuthor: {},
getArticle: {},
getArticleContent: [],
getRecommendProducts: [],
footer: {},
zanBar: {},
tagBar: [],
};
const data = await this.$api.get('/api/guang/article/detail', {
article_id
});
if (!data || data.code !== 200) {
result.code = 400;
return Promise.reject(result);
}
let article = (result.getArticle = (data && data.data) || {});
let promises = [
this.$api.post('/api/guang/article/content', { article_id }),
this.$api.post('/api/guang/article/zan', { articleId: grass_id })
];
const [content, zan] = await Promise.all(promises);
if (content && content.code === 200 && content.data) {
const processContents = guangProcess.processArticleDetail(content.data);
// 插入商品
const [goodsList, favsList] = await Promise.all([
this.$api.post('/api/guang/article/queryGoods', {
query: processContents.allgoods.skn.join(','),
order: 's_t_desc',
limit: processContents.allgoods.skn.length || 1
}),
this.$api.post('/api/favorite/batchCheckIsFavorite', {
favIds: processContents.allgoods.id.join(','),
type: 'product'
})
]).then(([res1, res2]) => {
return [get(res1, 'data.product_list', []), get(res2, 'data', [])];
});
result.getArticleContent = guangProcess.pushGoodsInfo(
processContents.finalDetail,
goodsList,
favsList
);
result.getRecommendProducts = processContents.recommends;
}
if (zan && zan.code === 200 && zan.data) {
result.footer = zan.data;
result.footer.articleId = grass_id;
result.zanBar.praiseHeadIco = result.footer.praiseHeadIco;
result.zanBar.praiseCount = result.footer.praiseCount;
result.zanBar.publish_time = article.publish_time;
// author
result.getAuthor.authorUid = zan.data.authorUid;
result.getAuthor.name = zan.data.authorName;
result.getAuthor.avatar = zan.data.authorHeadIco;
result.getAuthor.authorType = zan.data.authorType;
result.getAuthor.follow = get(zan, 'data.hasAttention', false) === 'Y';
}
if (article && article.tags) {
result.tagBar = article.tags;
}
commit(Types.FETCH_GUANG_SUCCESS, result);
}
};