Authored by ccbikai

频道页面数据结构优化

... ... @@ -11,16 +11,27 @@ const log = require('../../../library/logger');
const cookie = require('../../../library/cookie');
const mod = 'channel';
let footerTab = {
const renderData = {
module: mod,
page: 'home',
lifestyleHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: {
indexUrl: helpers.url('/?go=1'), // 首页
categoryUrl: helpers.url('/cate'), // 分类
guangUrl: helpers.url('', null, 'guang'), // 逛首页
shoppingCartUrl: helpers.url('/cart/index/index'), // 购物车
mineUrl: helpers.url('/home') // 个人中心
},
pageFooter: true
};
const channelLogger = (err) => {
log.error(err);
const channelLogger = (err, res) => {
log.error('频道页面渲染错误:' + JSON.stringify(err));
res.send('error');
};
/**
... ... @@ -51,19 +62,12 @@ exports.boys = (req, res) => {
gender: 'boys',
uid: cookie.getUid(req)
}).then(result => {
res.render('channel', Object.assign({
module: mod,
page: 'home',
title: '男生首页',
boysHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: footerTab,
pageFooter: true
res.render('channel', Object.assign(renderData, {
title: '男生首页'
}, result));
}).catch(channelLogger);
}).catch((err) => {
channelLogger(err, res);
});
};
exports.girls = (req, res) => {
... ... @@ -71,19 +75,12 @@ exports.girls = (req, res) => {
gender: 'girls',
uid: cookie.getUid(req)
}).then(result => {
res.render('channel', Object.assign({
module: mod,
page: 'home',
title: '女生首页',
girlsHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: footerTab,
pageFooter: true
res.render('channel', Object.assign(renderData, {
title: '女生首页'
}, result));
}).catch(channelLogger);
}).catch((err) => {
channelLogger(err, res);
});
};
exports.kids = (req, res) => {
... ... @@ -91,19 +88,12 @@ exports.kids = (req, res) => {
gender: 'kids',
uid: cookie.getUid(req)
}).then(result => {
res.render('channel', Object.assign({
module: mod,
page: 'home',
title: '潮童首页',
kidsHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: footerTab,
pageFooter: true
res.render('channel', Object.assign(renderData, {
title: '潮童首页'
}, result));
}).catch(channelLogger);
}).catch((err) => {
channelLogger(err, res);
});
};
exports.lifestyle = (req, res) => {
... ... @@ -111,19 +101,12 @@ exports.lifestyle = (req, res) => {
gender: 'lifestyle',
uid: cookie.getUid(req)
}).then(result => {
res.render('channel', Object.assign({
module: mod,
page: 'home',
title: '创意生活首页',
lifestyleHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: footerTab,
pageFooter: true
res.render('channel', Object.assign(renderData, {
title: '创意生活首页'
}, result));
}).catch(channelLogger);
}).catch((err) => {
channelLogger(err, res);
});
};
exports.bottomBanner = (req, res) => {
... ... @@ -131,5 +114,7 @@ exports.bottomBanner = (req, res) => {
channelModel.getBottomBannerDate(gender).then(result => {
res.send(result);
}).catch(console.trace);
}).catch((err) => {
channelLogger(err, res);
});
};
... ...