...
|
...
|
@@ -12,6 +12,11 @@ const logger = global.yoho.logger; |
|
|
|
|
|
// const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
|
|
* 资讯首页tab数据处理
|
|
|
* @param type
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _processNavData = (list, type) => {
|
|
|
let formatData = [];
|
|
|
|
...
|
...
|
@@ -20,7 +25,7 @@ const _processNavData = (list, type) => { |
|
|
|
|
|
_.forEach(list, (data, index) => {
|
|
|
data.url = `/editorial?type=${data.id}`;
|
|
|
data.isActive = index === parseInt(type, 10) ? true : false;
|
|
|
data.isActive = index === parseInt(type, 10);
|
|
|
|
|
|
formatData.push(data);
|
|
|
});
|
...
|
...
|
@@ -28,6 +33,13 @@ const _processNavData = (list, type) => { |
|
|
return formatData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 首页、列表页列表数据处理
|
|
|
* @param type
|
|
|
* @param pageNum
|
|
|
* @param limit
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _processListData = (list) => {
|
|
|
|
|
|
list = list || [];
|
...
|
...
|
@@ -59,19 +71,28 @@ const _processListData = (list) => { |
|
|
return listData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 资讯首页tab
|
|
|
* @param type
|
|
|
*/
|
|
|
const _getResources = (type) => {
|
|
|
return serviceAPI.get('guang/api/v1/category/get', {}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return _processNavData(result.data, type);
|
|
|
} else {
|
|
|
|
|
|
logger.error('资讯首页导航数据返回 code 不是 200');
|
|
|
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 首页、列表页列表相关
|
|
|
* @param type
|
|
|
* @param pageNum
|
|
|
* @param limit
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getBreakingSort = (type, pageNum, limit) => {
|
|
|
return serviceAPI.get('guang/api/*/article/getList', {
|
|
|
sort_id: type,
|
...
|
...
|
@@ -87,6 +108,13 @@ const _getBreakingSort = (type, pageNum, limit) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 首页接口
|
|
|
* @param type
|
|
|
* @param pageNum
|
|
|
* @param limit
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const getIndexData = (type, pageNum, limit) => {
|
|
|
return Promise.all([_getResources(type), _getBreakingSort(type, pageNum, limit)])
|
|
|
.then((result) => {
|
...
|
...
|
@@ -97,6 +125,14 @@ const getIndexData = (type, pageNum, limit) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 列表页接口
|
|
|
* @param type
|
|
|
* @param pageNum
|
|
|
* @param limit
|
|
|
* @param authorId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const getListData = (pageNum, limit, tag, authorId) => {
|
|
|
let param = {
|
|
|
page: pageNum,
|
...
|
...
|
@@ -121,7 +157,11 @@ const getListData = (pageNum, limit, tag, authorId) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 详情页
|
|
|
/**
|
|
|
* 获取详情页文章作者信息
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getAuthorData = (id) => {
|
|
|
|
|
|
return serviceAPI.get('/guang/service/*/author/getAuthor', {
|
...
|
...
|
@@ -136,6 +176,11 @@ const _getAuthorData = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 详情页文章头部基本信息内容数据处理
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _processHeadData = (list) => {
|
|
|
return co(function*() {
|
|
|
list = list || [];
|
...
|
...
|
@@ -212,6 +257,11 @@ const _processHeadData = (list) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 详情页文章内容数据处理
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _processContentData = (list) => {
|
|
|
list = list || [];
|
|
|
list = camelCase(list);
|
...
|
...
|
@@ -241,7 +291,11 @@ const _processContentData = (list) => { |
|
|
return contentData;
|
|
|
};
|
|
|
|
|
|
// head数据
|
|
|
/**
|
|
|
* 获取详情页头部信息
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getHeadData = (id) => {
|
|
|
return serviceAPI.get('/guang/api/*/article/getArticleBaseInfo', {
|
|
|
id: id
|
...
|
...
|
@@ -255,7 +309,11 @@ const _getHeadData = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// // content数据
|
|
|
/**
|
|
|
* 获取详情页文章内容
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getContentData = (id) => {
|
|
|
return serviceAPI.get('/guang/service/*/article/getArticleContent', {
|
|
|
article_id: id
|
...
|
...
|
@@ -269,7 +327,11 @@ const _getContentData = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// // 文章信息
|
|
|
/**
|
|
|
* 获取详情页文章基本信息
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getArticleData = (id) => {
|
|
|
return serviceAPI.get('/guang/service/v2/article/getArticle', {
|
|
|
article_id: id
|
...
|
...
|
@@ -283,7 +345,11 @@ const _getArticleData = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 评论列表
|
|
|
/**
|
|
|
* 获取详情页评论列表数据
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getCommentsData = (id) => {
|
|
|
return serviceAPI.get('/guang/api/*/comments/getList', {
|
|
|
article_id: id
|
...
|
...
|
@@ -297,7 +363,11 @@ const _getCommentsData = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 相关品牌
|
|
|
/**
|
|
|
* 获取详情页相关品牌数据
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getRelateBrand = (id) => {
|
|
|
return serviceAPI.get('guang/service/v2/article/getBrand', {
|
|
|
article_id: id
|
...
|
...
|
@@ -311,7 +381,12 @@ const _getRelateBrand = (id) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 资讯收藏
|
|
|
/**
|
|
|
* 资讯收藏
|
|
|
* @param uid
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const setCollect = (id, uid) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
...
|
...
|
@@ -325,7 +400,12 @@ const setCollect = (id, uid) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 取消收藏
|
|
|
/**
|
|
|
* 取消收藏
|
|
|
* @param uid
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const cancelCollect = (id, uid) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
...
|
...
|
@@ -339,7 +419,12 @@ const cancelCollect = (id, uid) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 点赞
|
|
|
/**
|
|
|
* 点赞
|
|
|
* @param uid
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const setPraise = (id, udid) => {
|
|
|
|
|
|
return serviceAPI.get('/guang/api/*/praise/setPraise', {
|
...
|
...
|
@@ -348,7 +433,12 @@ const setPraise = (id, udid) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 取消点赞
|
|
|
/**
|
|
|
* 取消点赞
|
|
|
* @param uid
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const cancelPraise = (id, udid) => {
|
|
|
|
|
|
return serviceAPI.get('/guang/api/*/praise/cancel', {
|
...
|
...
|
@@ -357,7 +447,13 @@ const cancelPraise = (id, udid) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
// 添加评论
|
|
|
/**
|
|
|
* 添加评论
|
|
|
* @param uid
|
|
|
* @param id
|
|
|
* @param comment
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const addComment = (id, uid, comment) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
...
|
...
|
@@ -372,6 +468,11 @@ const addComment = (id, uid, comment) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取详情页相关数据
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const getDetailData = (id) => {
|
|
|
return co(function *() {
|
|
|
let result = yield Promise.all([_getHeadData(id),
|
...
|
...
|
|