...
|
...
|
@@ -10,10 +10,15 @@ const _ = require('lodash'); |
|
|
const ServiceAPI = require(`${library}/api`).ServiceAPI;
|
|
|
const sign = require(`${library}/sign`);
|
|
|
const camelCase = require(`${library}/camel-case`);
|
|
|
const logger = require(`${library}/logger`);
|
|
|
const resourcesProcess = require(`${utils}/resources-process`);
|
|
|
|
|
|
const api = new ServiceAPI();
|
|
|
|
|
|
/**
|
|
|
* 性别数据
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
const genderData = {
|
|
|
boys: '1,3',
|
|
|
girls: '2,3'
|
...
|
...
|
@@ -27,7 +32,8 @@ const contentCode = { |
|
|
boys: '8512bf0755cc549ac323f852c9fd945d',
|
|
|
girls: '189b6686065dbd6755dd6906cf03c002',
|
|
|
kids: 'b8c1bff53d4ea60f978926d538620636',
|
|
|
lifestyle: '61cd852c6afcf60660196154f66a3a62'
|
|
|
lifestyle: '61cd852c6afcf60660196154f66a3a62',
|
|
|
index: '7ba9118028f9b22090b57341487567eb'
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -40,6 +46,33 @@ const bottomBannerCode = { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 频道选择页 默认数据
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
const channelList = {
|
|
|
1: {
|
|
|
href: '/boys',
|
|
|
title: '男生',
|
|
|
entitle: 'BOYS'
|
|
|
},
|
|
|
2: {
|
|
|
href: '/girls',
|
|
|
title: '女生',
|
|
|
entitle: 'GIRLS'
|
|
|
},
|
|
|
3: {
|
|
|
href: '/kids',
|
|
|
title: '潮童',
|
|
|
entitle: 'KIDS'
|
|
|
},
|
|
|
4: {
|
|
|
href: '/lifestyle',
|
|
|
title: '创意生活',
|
|
|
entitle: 'LIFESTYLE'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取二级菜单顶部颜色
|
|
|
* @param {[string]} choosed
|
|
|
* @return {[string]}
|
...
|
...
|
@@ -111,10 +144,11 @@ const getChannelResource = (params) => { |
|
|
params.new_device = true; // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
return api.get('operations/api/v5/resource/home', sign.apiSign(params), 300).then(result => {
|
|
|
return api.get('operations/api/v5/resource/home', sign.apiSign(params), true).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
return resourcesProcess(result.data.list);
|
|
|
} else {
|
|
|
logger.error('首页资源位接口返回状态码 不是 200');
|
|
|
return result;
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -128,24 +162,84 @@ const getChannelResource = (params) => { |
|
|
const getLeftNav = (choosed) => {
|
|
|
choosed = choosed || 'all';
|
|
|
|
|
|
return api.get('operations/api/v6/category/getCategory', sign.apiSign({}), 300).then(result => {
|
|
|
return api.get('operations/api/v6/category/getCategory', sign.apiSign({}), true).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
return processSideBar(result.data, choosed);
|
|
|
} else {
|
|
|
logger.error('侧边栏数据接口返回状态码 不是 200');
|
|
|
return result;
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取频道选择页数据
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
const getChannelList = () => {
|
|
|
return api.get('operations/api/v5/entrance/getEntrance', sign.apiSign({}), true).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
const list = {};
|
|
|
|
|
|
result.data.list = camelCase(result.data.list || []);
|
|
|
|
|
|
_.forEach(result.data.list, function(item) {
|
|
|
const channel = channelList[item.channelId];
|
|
|
|
|
|
if (channel) {
|
|
|
list[item.channelId] = channelList[item.channelId];
|
|
|
}
|
|
|
|
|
|
if (_.toNumber(item.channelId) === 5) {
|
|
|
list.showYohood = true;
|
|
|
list.yohoodHref = 'http://yohood.cn';
|
|
|
}
|
|
|
});
|
|
|
return Object.keys(list).length ? list : channelList;
|
|
|
} else {
|
|
|
logger.error('频道选择接口返回状态码 不是 200');
|
|
|
return channelList;
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取频道选择页 背景
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
const getChannelBg = () => {
|
|
|
return api.get('operations/api/v5/resource/get', sign.apiSign({
|
|
|
content_code: contentCode.index
|
|
|
}), true).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
|
|
|
} else {
|
|
|
logger.error('频道选择页背景图接口返回状态码 不是 200');
|
|
|
return {
|
|
|
src: ''
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取频道选择页面数据
|
|
|
* @param {[string]} gender
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
exports.getChannelSwitchData = () => {
|
|
|
return Promise.all([getChannelList(), getChannelBg()]);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取频道页面数据
|
|
|
* @param {[object]} params
|
|
|
* @return {[object]}
|
|
|
*/
|
|
|
exports.getChannelDate = (params) => {
|
|
|
exports.getChannelData = (params) => {
|
|
|
var channelData = {};
|
|
|
|
|
|
return api.all([getChannelResource(params), getLeftNav(params.gender)]).then((data) => {
|
|
|
return Promise.all([getChannelResource(params), getLeftNav(params.gender)]).then((data) => {
|
|
|
channelData.content = data[0]; // 资源位数据
|
|
|
channelData.sideNav = data[1]; // 侧边栏数据
|
|
|
|
...
|
...
|
@@ -158,13 +252,13 @@ exports.getChannelDate = (params) => { |
|
|
* @param {[string]} gender
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
exports.getBottomBannerDate = (gender) => {
|
|
|
exports.getBottomBannerData = (gender) => {
|
|
|
gender = gender || 'boys';
|
|
|
|
|
|
if (gender === 'boys' || gender === 'girls') {
|
|
|
return api.get('operations/api/v5/resource/get', sign.apiSign({
|
|
|
content_code: bottomBannerCode[gender] // eslint-disable-line
|
|
|
}));
|
|
|
}), true);
|
|
|
}
|
|
|
return Promise.resolve({
|
|
|
code: 400,
|
...
|
...
|
|