actions.js
3.32 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
import * as Types from './types';
import { get } from 'lodash';
import * as guangProcess from './guangProcess';
export default {
async fetchArticleList({ commit }, { articleId, limit = 5, page = 1 }) {
commit(Types.FETCH_ARTICLE_DETAIL_REQUEST);
const result = await this.$api.get('/api/grass/columnArticleDetail', {
articleId,
limit,
page,
columnType: 1001
});
if (result && result.code === 200) {
if (!result.data.detailList) {
result.data.detailList = [];
}
commit(Types.FETCH_ARTICLE_DETAIL_SUCCESS, {
data: result.data.detailList,
page
});
} else {
commit(Types.FETCH_ARTICLE_DETAIL_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 result;
}
let article = result.getArticle = data && data.data || {};
let promises = [
this.$api.get('/api/guang/article/author', { author_id: article.author_id }),
this.$api.get('/api/guang/article/content', { article_id }),
this.$api.get('/api/guang/article/zan', { articleId: grass_id })
];
const [author, content, zan] = await Promise.all(promises);
if (author && author.code === 200 && author.data) {
result.getAuthor = author.data;
}
if (content && content.code === 200 && content.data) {
const recommendProducts = content.data.filter(i => 'recommend_products' in i).reduce((t, c) => {
t = t.concat(c.recommend_products.data);
return t;
}, []);
result.getRecommendProducts = recommendProducts;
const processContents = guangProcess.processArticleDetail(content.data);
// 插入商品
const goodsList = await this.$api.get('/api/guang/article/queryGoods', {
query: processContents.allgoods.join(','),
order: 's_t_desc',
limit: processContents.allgoods.length || 1
}).then(res => {
return get(res, 'data.product_list', []);
});
result.getArticleContent = guangProcess.pushGoodsInfo(processContents.finalDetail, goodsList);
}
if (zan && zan.code === 200 && zan.data) {
result.footer = zan.data;
result.zanBar.praiseHeadIco = result.footer.praiseHeadIco;
result.zanBar.praiseCount = result.footer.praiseCount;
result.zanBar.publish_time = article.publish_time;
}
if (article && article.tags) {
result.tagBar = article.tags;
}
commit(Types.FETCH_GUANG_SUCCESS, result);
},
async setFav({ commit }, { status, articleId }) {
const FAV = {
0: 'N', // 取消
1: 'Y' // 收藏
};
const result = await this.$api.get('/api/guang/article/setFav', { isAdd: FAV[status], articleId });
commit(Types.FETCH_FAV_SUCCESS, result);
},
async setZan({ commit }, { status, articleId }) {
const ZAN = {
0: 1, // 取消
1: 0 // 收藏
};
const result = await this.$api.get('/api/guang/article/setZan', { status: ZAN[status], articleId });
commit(Types.FETCH_ZAN_SUCCESS, result);
},
};