...
|
...
|
@@ -6,17 +6,79 @@ |
|
|
'use strict';
|
|
|
const serviceAPI = global.yoho.ServiceAPI;
|
|
|
const api = global.yoho.API;
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
|
|
|
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
|
|
|
|
|
|
/**
|
|
|
* 获取二级菜单顶部颜色
|
|
|
* @param {[string]} choosed
|
|
|
* @return {[string]}
|
|
|
*/
|
|
|
const _getSidebarColor = (choosed) => {
|
|
|
let color = false;
|
|
|
|
|
|
if (choosed === 'girls') {
|
|
|
color = '#FF88AE';
|
|
|
} else if (choosed === 'kids') {
|
|
|
color = '#7ad9f9';
|
|
|
} else if (choosed === 'lifestyle') {
|
|
|
color = '#4f4138';
|
|
|
}
|
|
|
|
|
|
return color;
|
|
|
};
|
|
|
|
|
|
//微信侧边栏导航数据
|
|
|
const _processSideBar = (list, choosed) => {
|
|
|
const formatData = [];
|
|
|
let offset = 0; // 分割数组用到的游标
|
|
|
|
|
|
list = list || [];
|
|
|
|
|
|
_.forEach(list, (item, i) => {
|
|
|
if (item.sub) {
|
|
|
item.sub.unshift({
|
|
|
sort_name: item.sort_name,
|
|
|
sort_name_en: item.sort_name_en,
|
|
|
back: true,
|
|
|
isSelect: false,
|
|
|
bgColor: _getSidebarColor(choosed)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 如果有分隔符,分割数组
|
|
|
if (item.separative_sign === 'Y') {
|
|
|
formatData.push(list.slice(offset, i));
|
|
|
offset = i;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 数组被分割剩余的部分
|
|
|
formatData.push(list.slice(offset));
|
|
|
return formatData;
|
|
|
};
|
|
|
|
|
|
const _getLeftNav = (choosed) => {
|
|
|
choosed = choosed || 'all';
|
|
|
|
|
|
return serviceAPI.get('operations/api/v6/category/getCategory', {}, {
|
|
|
cache: true
|
|
|
}).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
|
|
|
return _processSideBar(result.data, choosed);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* [逛资讯详情页数据封装]
|
|
|
* @param {[int]} id [内容ID]
|
|
|
* @param {Boolean} isApp [标识是否是APP访问]
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
const packageData = (id, isApp) => {
|
|
|
const packageData = (id, isApp, isWeixin, channel) => {
|
|
|
let result = {
|
|
|
getAuthor: {},
|
|
|
getArticle: {},
|
...
|
...
|
@@ -112,6 +174,13 @@ const packageData = (id, isApp) => { |
|
|
}));
|
|
|
}
|
|
|
|
|
|
|
|
|
if (isWeixin) {
|
|
|
let navGender = _.cloneDeep(channel);
|
|
|
|
|
|
promises.push(_getLeftNav(navGender));
|
|
|
}
|
|
|
|
|
|
return Promise.all(promises).then(datas => {
|
|
|
|
|
|
let getArticleContent = {};
|
...
|
...
|
@@ -140,6 +209,7 @@ const packageData = (id, isApp) => { |
|
|
weixinPublic: datas[4].data
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (datas[0]) {
|
|
|
result.getAuthor = datas[0].data;
|
|
|
}
|
...
|
...
|
@@ -148,7 +218,12 @@ const packageData = (id, isApp) => { |
|
|
if (datas[2]) {
|
|
|
result.getBrand = datas[2].data;
|
|
|
}
|
|
|
if (datas.length === 5 && isApp || datas.length === 4 && !isApp) {
|
|
|
|
|
|
if (isWeixin && datas[4]) {
|
|
|
result.sideNav = datas[4];
|
|
|
}
|
|
|
|
|
|
if (datas.length === 5 && isApp || datas.length === 4 && !isApp || datas.length === 5 && isWeixin) {
|
|
|
if (datas[3]) {
|
|
|
result.getOtherArticle = datas[3].data;
|
|
|
}
|
...
|
...
|
|