|
|
import * as Types from './types';
|
|
|
import { get } from 'lodash';
|
|
|
import { get, concat } from 'lodash';
|
|
|
import * as guangProcess from './guangProcess';
|
|
|
|
|
|
|
|
|
export default {
|
|
|
async fetchArticleList({ commit }, { articleId, limit = 5, page = 1 }) {
|
|
|
commit(Types.FETCH_ARTICLE_DETAIL_REQUEST);
|
...
|
...
|
@@ -104,56 +103,59 @@ export default { |
|
|
|
|
|
if (!data || data.code !== 200) {
|
|
|
result.code = 400;
|
|
|
return result;
|
|
|
return Promise.reject(result);
|
|
|
}
|
|
|
|
|
|
let article = result.getArticle = data && data.data || {};
|
|
|
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;
|
|
|
result.getAuthor.authorUid = result.getAuthor.author_id;
|
|
|
result.getAuthor.fellow = get(zan, 'data.hasAttention', false);
|
|
|
}
|
|
|
const [content, zan] = await Promise.all(promises);
|
|
|
|
|
|
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, favsList] = await Promise.all([this.$api.get('/api/guang/article/queryGoods', {
|
|
|
query: processContents.allgoods.join(','),
|
|
|
order: 's_t_desc',
|
|
|
limit: processContents.allgoods.length || 1
|
|
|
}), this.$api.get('/api/favorite/batchCheckIsFavorite', {
|
|
|
favIds: processContents.allgoods.join(','),
|
|
|
type: 'product'
|
|
|
})]).then(([res1, res2]) => {
|
|
|
const [goodsList, favsList] = await Promise.all([
|
|
|
this.$api.get('/api/guang/article/queryGoods', {
|
|
|
query: processContents.allgoods.join(','),
|
|
|
order: 's_t_desc',
|
|
|
limit: processContents.allgoods.length || 1
|
|
|
}),
|
|
|
this.$api.get('/api/favorite/batchCheckIsFavorite', {
|
|
|
favIds: processContents.allgoods.join(','),
|
|
|
type: 'product'
|
|
|
})
|
|
|
]).then(([res1, res2]) => {
|
|
|
return [get(res1, 'data.product_list', []), get(res2, 'data', [])];
|
|
|
});
|
|
|
|
|
|
result.getArticleContent = guangProcess.pushGoodsInfo(processContents.finalDetail, goodsList, favsList);
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
if (article && article.tags) {
|
...
|
...
|
@@ -161,27 +163,5 @@ export default { |
|
|
}
|
|
|
|
|
|
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);
|
|
|
},
|
|
|
|
|
|
}
|
|
|
}; |
...
|
...
|
|