Authored by ccbikai

函数修改

... ... @@ -9,7 +9,7 @@ const _ = require('lodash');
const channelModel = require('../models/channel');
const helpers = require(`${library}/helpers`);
const renderData = {
let _renderData = {
module: 'channel',
page: 'home',
homeHeader: {
... ... @@ -33,19 +33,19 @@ const renderData = {
* @param {[object]} data 自定义数据
* @return {[type]}
*/
const channelPage = (req, res, data) => {
let _channelPage = (req, res, data) => {
return channelModel.getChannelData({ // TODO 内部的Promise方法必须 return 出来
gender: data.gender,
uid: _.toString(req.user.uid)
}).then(result => {
res.render('channel', Object.assign({}, renderData, data, result));
res.render('channel', Object.assign({}, _renderData, data, result));
});
};
/**
* 频道选择页
*/
exports.index = (req, res, next) => {
let index = (req, res, next) => {
channelModel.getChannelSwitchData().then((result) => {
res.render('index', {
module: 'channel',
... ... @@ -67,7 +67,7 @@ exports.index = (req, res, next) => {
* @param {Function} next
* @return {Function}
*/
exports.switchChannel = (req, res, next) => {
let switchChannel = (req, res, next) => {
let channel = req.cookies._Channel;
// 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页
... ... @@ -83,8 +83,8 @@ exports.switchChannel = (req, res, next) => {
/**
* 男生首页
*/
exports.boys = (req, res, next) => {
channelPage(req, res, {
let boys = (req, res, next) => {
_channelPage(req, res, {
gender: 'boys',
title: '男生首页',
boysHomePage: true
... ... @@ -94,8 +94,8 @@ exports.boys = (req, res, next) => {
/**
* 女生首页
*/
exports.girls = (req, res, next) => {
channelPage(req, res, {
let girls = (req, res, next) => {
_channelPage(req, res, {
gender: 'girls',
title: '女生首页',
girlsHomePage: true
... ... @@ -106,8 +106,8 @@ exports.girls = (req, res, next) => {
* 潮童首页
*/
exports.kids = (req, res, next) => {
channelPage(req, res, {
let kids = (req, res, next) => {
_channelPage(req, res, {
gender: 'kids',
title: '潮童首页',
kidsHomePage: true
... ... @@ -117,8 +117,8 @@ exports.kids = (req, res, next) => {
/**
* 创意生活首页
*/
exports.lifestyle = (req, res, next) => {
channelPage(req, res, {
let lifestyle = (req, res, next) => {
_channelPage(req, res, {
gender: 'lifestyle',
title: '创意生活首页',
lifestyleHomePage: true
... ... @@ -131,10 +131,20 @@ exports.lifestyle = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
exports.bottomBanner = (req, res, next) => {
let bottomBanner = (req, res, next) => {
let gender = req.query.gender || 'boys';
channelModel.getBottomBannerData(gender).then(result => {
res.send(result);
}).catch(next);
};
module.exports = {
switchChannel,
index,
boys,
girls,
kids,
lifestyle,
bottomBanner
};
... ...
... ... @@ -9,7 +9,6 @@ const utils = '../../../utils';
const contentCodeConfig = require('../../../config/content-code');
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`);
... ... @@ -67,7 +66,7 @@ const channelList = [
* @param {[string]} choosed
* @return {[string]}
*/
const getSidebarColor = (choosed) => {
const _getSidebarColor = (choosed) => {
let color = false;
if (choosed === 'girls') {
... ... @@ -86,7 +85,7 @@ const getSidebarColor = (choosed) => {
* @param {[array]} list
* @return {[array]}
*/
const processSideBar = (list, choosed) => {
const _processSideBar = (list, choosed) => {
const formatData = [];
let offset = 0; // 分割数组用到的游标
... ... @@ -100,7 +99,7 @@ const processSideBar = (list, choosed) => {
sortNameEn: item.sortNameEn,
back: true,
isSelect: false,
bgColor: getSidebarColor(choosed)
bgColor: _getSidebarColor(choosed)
});
}
... ... @@ -121,7 +120,7 @@ const processSideBar = (list, choosed) => {
* @param {[object]} gender
* @return {[type]}
*/
const getChannelResource = (params) => {
const _getChannelResource = (params) => {
params.gender = params.gender || 'boys';
params = Object.assign({
... ... @@ -134,7 +133,7 @@ const getChannelResource = (params) => {
params.new_device = true; // eslint-disable-line
}
return api.get('operations/api/v5/resource/home', sign.apiSign(params), true).then(result => {
return api.get('operations/api/v5/resource/home', params, true).then(result => {
if (result && result.code === 200) {
return resourcesProcess(result.data.list);
} else {
... ... @@ -149,12 +148,12 @@ const getChannelResource = (params) => {
* @param {[string]} choosed
* @return {[object]}
*/
const getLeftNav = (choosed) => {
const _getLeftNav = (choosed) => {
choosed = choosed || 'all';
return api.get('operations/api/v6/category/getCategory', sign.apiSign({}), true).then(result => {
return api.get('operations/api/v6/category/getCategory', {}, true).then(result => {
if (result && result.code === 200) {
return processSideBar(result.data, choosed);
return _processSideBar(result.data, choosed);
} else {
logger.error('侧边栏数据接口返回状态码 不是 200');
return result;
... ... @@ -166,8 +165,8 @@ const getLeftNav = (choosed) => {
* 获取频道选择页数据
* @return {[type]}
*/
const getChannelList = () => {
return api.get('operations/api/v5/entrance/getEntrance', sign.apiSign({}), true).then((result) => {
const _getChannelList = () => {
return api.get('operations/api/v5/entrance/getEntrance', {}, true).then((result) => {
if (result && result.code === 200) {
const list = {};
... ... @@ -199,10 +198,10 @@ const getChannelList = () => {
* 获取频道选择页 背景
* @return {[type]}
*/
const getChannelBg = () => {
return api.get('operations/api/v5/resource/get', sign.apiSign({
const _getChannelBg = () => {
return api.get('operations/api/v5/resource/get', {
content_code: contentCode.index
}), true).then(result => {
}, 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 {
... ... @@ -219,8 +218,8 @@ const getChannelBg = () => {
* @param {[string]} gender
* @return {[type]}
*/
exports.getChannelSwitchData = () => {
return Promise.all([getChannelList(), getChannelBg()]);
let getChannelSwitchData = () => {
return Promise.all([_getChannelList(), _getChannelBg()]);
};
/**
... ... @@ -228,10 +227,10 @@ exports.getChannelSwitchData = () => {
* @param {[object]} params
* @return {[object]}
*/
exports.getChannelData = (params) => {
let getChannelData = (params) => {
var channelData = {};
return Promise.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]; // 侧边栏数据
... ... @@ -244,13 +243,13 @@ exports.getChannelData = (params) => {
* @param {[string]} gender
* @return {[type]}
*/
exports.getBottomBannerData = (gender) => {
let getBottomBannerData = (gender) => {
gender = gender || 'boys';
if (gender === 'boys' || gender === 'girls') {
return api.get('operations/api/v5/resource/get', sign.apiSign({
return api.get('operations/api/v5/resource/get', {
content_code: bottomBannerCode[gender] // eslint-disable-line
}), true);
}, true);
}
return Promise.resolve({
code: 400,
... ... @@ -258,3 +257,9 @@ exports.getBottomBannerData = (gender) => {
message: '参数错误'
});
};
module.exports = {
getChannelData,
getChannelSwitchData,
getBottomBannerData
};
... ...